Database¶
The database and connection to it is managed by the database
module. The database is a PostgreSQL database and its structure is defined in the database.models
module.
Connections to the database and transactions are managed by SQLAlchemy ORM, available queries are defined in the database.services
module.
At the start of the app, database.database.get_engine()
is called to instantiate an engine and a sessionmaker.
- Engine
Create and manage connections to the database
- Sessionmaker
Create a session object which is used to interact with the database.
Every time a request is made to the server, a new session is created through database.database.get_db()
and used to interact with the database. After the request is finished, the session is closed.
- database.database.get_db()¶
Get a database connection
- Return type:
Session
- database.database.get_engine(configuration: DBConfiguration, retries: int = 10, delay: int = 5)¶
Get an engine object that manages connection to the database
- Parameters:
configuration (DBConfiguration) – Database configuration
retries (int) – Number of retries before giving up on connecting to the database
delay (int) – Delay between each retries
- Return type:
Engine