database.session_overrides

This mixin overrides some of sqlalchemy session’s in built methods to provide accounting specific behavior. It also provides custom methods specific to accounting.

Module Contents

Classes

SessionOverridesMixin

Session overrides class.

class database.session_overrides.SessionOverridesMixin

Session overrides class.

get(model, primary_key, **kwargs) sqlalchemy.orm.Mapped[Base]

Overrides sqlalchemy the get method to use select thereby ensuring global filters are applied.

Parameters:
  • model (DeclarativeBase) – The model class.

  • primary_key (int) – The primary key of the instance being fetched.

Returns:

The model instance if found, else None.

delete(instance) bool

Overrides the sqlalchemy delete method to enable model recycling.

Parameters:

instance (DeclarativeBase) – The model instance.

Returns:

True if successful, else False.

Raises:

SessionEntityError – If the instance being deleted is the session Entity.

restore(instance) bool

Restore a deleted/recycled model instance.

Parameters:

instance (DeclarativeBase) – The model instance.

Returns:

True if successful, else False.

destroy(instance) bool

Mark a model instance as destroyed, i.e. permanently delete.

Parameters:

instance (DeclarativeBase) – The model instance.

Returns:

True.

erase(instance) bool

Completely remove an instance from the database.

Parameters:

instance (DeclarativeBase) – The model instance.

Returns:

True.