API Reference
AllDatabaseSettings
Bases: BaseModel
Settings for the database connection.
Source code in db4me/settings.py
ConfigurationError
Bases: Db4MeError
Raised when there is an error in the configuration file.
DatabaseSettings
Bases: BaseModel
Common settings for all database types.
Attributes:
Name | Type | Description |
---|---|---|
url |
Optional[str]
|
The database URL. In case of async connections this is where the async database URL should be set. |
sync_alternative |
Optional[str]
|
The database URL to use for sync connections. This
should be used when an async connection exists in |
echo |
Optional[bool]
|
If True, the engine will log all statements as well as a repr() of their parameter lists to the engines logger, which defaults to sys.stdout. |
pool_size |
Optional[int]
|
The size of the database pool. |
pool_recycle |
Optional[int]
|
The number of seconds after which a database connection should be recycled. |
pool_pre_ping |
Optional[bool]
|
If True, the database connection pool will be pre-pinged This means that the connection will be checked if it is still alive before it is used. |
pool_reset_on_return |
Optional[str]
|
The action to take when a connection is returned to the pool. Possible values are: - "rollback": Rollback the transaction. - "commit": Commit the transaction. - "disconnect": Disconnect the connection. |
Source code in db4me/settings.py
validate_sync_alternative(v, values)
classmethod
Validate the sync_alternative field.
Source code in db4me/settings.py
Db4MeError
PgDatabaseSettings
SqliteDatabaseSettings
Bases: BaseModel
Settings for connections to SqLite databases.
Source code in db4me/settings.py
get_engine(stg, is_async=False)
Creates an engine based on settings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stg |
AllDatabaseSettings
|
The database settings. |
required |
is_async |
bool
|
Whether to create an async engine. |
False
|
Raises: ConfigurationError: If the database URL is not set.
Source code in db4me/connection.py
Database Connection
get_engine(stg, is_async=False)
Creates an engine based on settings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stg |
AllDatabaseSettings
|
The database settings. |
required |
is_async |
bool
|
Whether to create an async engine. |
False
|
Raises: ConfigurationError: If the database URL is not set.
Source code in db4me/connection.py
Settings
Pydantic models used in configuring the database.
AllDatabaseSettings
Bases: BaseModel
Settings for the database connection.
Source code in db4me/settings.py
DatabaseSettings
Bases: BaseModel
Common settings for all database types.
Attributes:
Name | Type | Description |
---|---|---|
url |
Optional[str]
|
The database URL. In case of async connections this is where the async database URL should be set. |
sync_alternative |
Optional[str]
|
The database URL to use for sync connections. This
should be used when an async connection exists in |
echo |
Optional[bool]
|
If True, the engine will log all statements as well as a repr() of their parameter lists to the engines logger, which defaults to sys.stdout. |
pool_size |
Optional[int]
|
The size of the database pool. |
pool_recycle |
Optional[int]
|
The number of seconds after which a database connection should be recycled. |
pool_pre_ping |
Optional[bool]
|
If True, the database connection pool will be pre-pinged This means that the connection will be checked if it is still alive before it is used. |
pool_reset_on_return |
Optional[str]
|
The action to take when a connection is returned to the pool. Possible values are: - "rollback": Rollback the transaction. - "commit": Commit the transaction. - "disconnect": Disconnect the connection. |
Source code in db4me/settings.py
validate_sync_alternative(v, values)
classmethod
Validate the sync_alternative field.
Source code in db4me/settings.py
PgDatabaseSettings
SqliteDatabaseSettings
Bases: BaseModel
Settings for connections to SqLite databases.
Source code in db4me/settings.py
Errors
ConfigurationError
Bases: Db4MeError
Raised when there is an error in the configuration file.