simplelogincmd.database.access_layer.DatabaseAccessLayer

class DatabaseAccessLayer(engine: Engine | None = None, declarative_base: Type | None = None, session_cls: Session | None = None)

Bases: object

Proxy between database consumers and the database itself

Ease testing, abstract away implementation details, and normalize database interaction by providing a single class whose instances contain everything necessary to manage the database and load, modify, and persist model objects.

Constructor

Parameters:
  • engine (sqlalchemy.engine.Engine, optional) – The SQLAlchemy engine which manages the db, defaults to an engine suited to the application

  • declarative_base (Type, subclass of sqlalchemy.orm.DeclarativeBase, optional) – The base class of all other database model classes, defaults to a base configured for the application

  • session_cls (Type, subclass of sqlalchemy.orm.session.Session, optional) – The type of session to be used for interacting with the db, defaults to a session suitable to the application

Methods

clear

Drop and re-initialize the database

destroy

Drop the entire database

initialize

Initialize the database if it does not already exist

clear() bool

Drop and re-initialize the database

Simple helper that calls destroy() and then, if that succeeds, “meth”.initialize.

Returns:

Whether the entire process of destruction and re-initialization succeeds

Return type:

bool

destroy() bool

Drop the entire database

Returns:

Whether the destruction succeeds

Return type:

bool

initialize() bool

Initialize the database if it does not already exist

Create the database, as well as all its tables, if it does not already exist. If it does, do nothing.

Returns:

Whether initialization succeeds

Return type:

bool