redirectory.libs_int.database.database_manager module

class redirectory.libs_int.database.database_manager.DatabaseManager[source]

Bases: object

create_db_tables()[source]

Will create all model’s tables associated with the current DatabaseManager base. The creation of those tables is safe. If a table already exists it will not be created again. If the DatabaseManager is not initialized then a ValueError will be raised.

delete_db_tables()[source]

Will drop all tables associated with the current base of the DatabaseManager. Every model’s table that inherits from this base will be dropped. If the DatabaseManager is not initialized then a ValueError will be raised.

get_base()[source]

Gets the current base that all models should inherit from. Once a model inherits from this base it will be associated with it.

Returns:the current base
get_session()[source]

Creates a scoped session with with the help of the session maker. This session is specific to the current thread from where this function is called. If a session already exists it will be returned but if not a new one will be created. If the DatabaseManager is not initialized then a ValueError will be raised.

Returns:a database session for the current thread
reload()[source]
return_session(session)[source]

Closes the given session and removes it from DatabaseManager to prevent from any further use. Sets the session of the DatabaseManager to None

Parameters:session – the session to remove
redirectory.libs_int.database.database_manager.get_connection_string()[source]

Generates a connection string to be passed to SQLAlchemy. The string is created from the current loaded configuration with the help of the Configuration() class. There are two options for both SQLite and MySQL database connections.

Returns:a connection string for SQLAlchemy to use for an engine