LazyAbstractDbManager
Abstract Database Manager that automatically handles Docker container startup logic.
Subclasses only need to define:
- get_name: Name of the DB for this brick
- get_brick_name: Name of the brick
Everything else (host, database name, port, credentials, network configuration) is handled automatically.
Example: class MyBrickDbManager(LazyAbstractDbManager): db = DatabaseProxy()
_instance: Optional['MyBrickDbManager'] = None
@classmethod
def get_instance(cls) -> 'MyBrickDbManager':
if cls._instance is None:
cls._instance = cls()
return cls._instance
def get_name(self) -> str:
return 'db'
def get_brick_name(self) -> str:
return 'my_brick'
db: DatabaseProxymode: OptionalCheck if the database connection is working
boolClose the db connection
Open the db connection
Create the tables for the provided models
listDrop the tables for the provided models
listExecute the provided sql command
strReturn the brick name for this database manager. Must be implemented by subclasses.
strGet database configuration with credentials from Docker service
LiteralDbConfigGet the db object
DatabaseProxyGet the db object
LiteralReturn the name of the DbManager. The combination of brick name and unique name must be unique accross all DbManager inheritors.
strstrCheck if there is an active transaction
boolIf True, errors during initialization from DbManagerService will be ignored If False, errors during initialization will raise exceptions
Useful if the database need to be initialized manually later (eg: downloaded first)
boolInitialize the database by starting the Docker container first
LiteralReturn if the db manager was initialized
boolThis DbManager is always lazy initialized.
boolTest if the mysql engine is active
Register a hook to be called after a transaction is committed
CallableClose all db managers
Get all the classes that inherit this class
setGet the singleton instance of this DbManager subclass
Must be called implement in sub concrete classes.
AbstractDbManagerReconnect all db managers
Decorator to create a new transaction around a method If an exception is raised, the transaction is rolled back
Can also be used as a context manager.
bool - FalseCallable