Menu
Introduction
Getting Started
Developer guide
Release
Architecture
CLI
Technical documentations
Version
Publication date

Mar 9, 2022

Confidentiality
Public
Reactions
1
Share

AbstractDbManager

DbManager class. Provides backend feature for managing databases. Implements a singleton pattern - each subclass has its own unique instance.

Implementation must define fillowing properties

:property db: Database Proxy :type db: DatabaseProxy

Attributes
db: DatabaseProxymode: Optional
Functions
check_connection

Check if the database connection is working

Return type : bool
close_db

Close the db connection

connect_db

Open the db connection

create_tables

Create the tables for the provided models

models : list
drop_tables

Drop the tables for the provided models

models : list
execute_sql

Execute the provided sql command

sql : str
get_brick_name
Return type : str
get_config
mode : Literal
Return type : DbConfig
get_db

Get the db object

Return type : DatabaseProxy
get_engine

Get the db object

Return type : Literal
get_name

Return the name of the DbManager. The combination of brick name and unique name must be unique accross all DbManager inheritors.

Return type : str
get_unique_name
Return type : str
has_transaction

Check if there is an active transaction

Return type : bool
ignore_error_on_init

If 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)

Return type : bool
init

Initialize the DbManager

mode : Literal
is_initialized

Return if the db manager was initialized

Return type : bool
is_lazy_init

If True, the db will be initialized after the app start, and app won't fail if db is not available If False, the db will be initialized immediately (not recommended), and app fails if db is not available

Return type : bool
is_mysql_engine

Test if the mysql engine is active

register_after_commit_hook

Register a hook to be called after a transaction is committed

hook : Callable
Hook to register
close_dbs @classmethod

Close all db managers

get_db_managers @classmethod

Get all the classes that inherit this class

Return type : set
get_instance @classmethod

Get the singleton instance of this DbManager subclass

Must be called implement in sub concrete classes.

Return type : AbstractDbManager
reconnect_dbs @classmethod

Reconnect all db managers

transaction @classmethod

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.

nested_transaction : bool - False
if False only 1 transaction is created at a time and it waits for the transaction to finish before creating a new one. If True, a transaction is created each time this method is called
Return type : Callable
Shine Logo
Technical bricks to reuse or customize

Have you developed a brick?

Share it to accelerate projects for the entire community.