Database

Schemas for the database config.

ALLOWED_DATABASES = ('sqlite', 'mysql', 'postgresql')

Tuple containing the allowed databases types

class DatabaseSchema(type='sqlite', host=None, database=None, port=None, username=None, password=None, connection_string=None)[source]

This class represents the [history.database] section of our config.toml file.

Notes

If you are running MySQL or MariaDB in a container and want to test it out, don’t set the host to “localhost”, but set it to “127.0.0.1”. The “localhost” will use the mysql socket connector, and “127.0.0.1” will use TCP connector.

Reference: https://stackoverflow.com/a/4448568

type

The database type to connect

Type:

str

host

The host for the database

Type:

Optional[str], optioanl

database

The name for the database

Type:

Optional[str], optioanl

port

The port of the database

Type:

Optional[int], optioanl

username

The username to connect

Type:

Optional[str], optioanl

password

The password to connect

Type:

Optional[str], optioanl

connection_string

Database path for sqlite

Type:

Optional[Union[str, Path]], optioanl

_read_credentials_from_systemd(identifier)[source]

Read the credentials from systemd folder.

Return type:

str

Note

This should only happen in case the username/password is not defined in the config file. This is a more secure way for the user to specify their credentials without relying on writing it un-encrypted in a configuration file.

Parameters:
  • identifier (str) – The identifier to be read from systemd

  • directory. (credentials)

Raises:
  • ValueError – In case the CREDENTIALS_DIRECTORY is not present or

  • the credential file is empty.

connection_string: Union[str, Path, None] = None
database: Optional[str] = None
get_connection_url()[source]

Constructs and returns the connection URL or string for the respective database.

Return type:

str

Raises:

ValueError – In case the type is not recognized

Returns:

The URL formatted connection

Return type:

str

host: Optional[str] = None
password: Optional[str] = None
port: Optional[int] = None
type: str = 'sqlite'
username: Optional[str] = None
SYSTEMD_PASSWORD_ID: str = 'database-password'

Name of the credential containing the password to be loaded

SYSTEMD_USERNAME_ID: str = 'database-username'

Name of the credential containing the username to be loaded