aleph.db.accessors package

Submodules

Module contents

Database access module.

This module abstracts queries for the rest of the application. The idea is that any query that is more complex than select(ModelClass) or session.add(model_instance) should be abstracted by a function in this module.

Suggested practices: * Functions should usually take a DbSession parameter instead of a DbSessionFactory.

This allows callers to reuse the same session through multiple calls to this module if they need it.

  • It is a good idea to separate the generation of the queries from their execution, especially for complex queries. This simplifies the audit of the queries generated by the ORM.

  • All the functions should be unit tested.

  • 1 file in db.models = db.accessors. Makes it easier to find where queries are implemented for each model.