db#

Attributes#

APP_SQLALCHEMY_ENGINE_OPTIONS

Custom configuration for SQLAlchemy

DB

An SQLAlchemy engine used to instantiate connections

FLASK_DB

A Flask-SQLAlchemy object, needed for per-request connection handling

Functions#

get_config(→ dict)

Returns the config in db/config.toml for the current environment

get_config_uri(→ str)

Returns the DB config as a single URI string

get_cli_connection_params(→ list[str])

Returns the DB config as a list of mysql client CLI parameters

get_connection()

Returns an SQLAlchemy Connection object.

get_session([conn])

Returns an SQLAlchemy Session object.

get_transaction()

Returns a database connection that is initialized in transaction mode

Package Contents#

db.APP_SQLALCHEMY_ENGINE_OPTIONS[source]#

Custom configuration for SQLAlchemy

db.get_config(env: str = None) dict[source]#

Returns the config in db/config.toml for the current environment

db.get_config_uri() str[source]#

Returns the DB config as a single URI string

db.get_cli_connection_params() list[str][source]#

Returns the DB config as a list of mysql client CLI parameters

db.get_connection()[source]#

Returns an SQLAlchemy Connection object.

Usually, the code will use an SQLAlchemy Session, but this function is used for direct queries that do not need the ORM setup. For the most part, this is migrations.

db.get_session(conn=None)[source]#

Returns an SQLAlchemy Session object.

This may be used to wrap an existing connection into an ORM-aware session. If the given connection is actually a Session, it simply returns it.

Part of the reason this is happening is because of legacy reasons, but it’s also used to wrap a transaction connection from get_transaction. Ideally, this shouldn’t be necessary, but getting transactions to work for sessions has been a pain and this was the combination of entities that got us there. It may be simplified in the future.

db.get_transaction()[source]#

Returns a database connection that is initialized in transaction mode

db.DB[source]#

An SQLAlchemy engine used to instantiate connections

db.FLASK_DB[source]#

A Flask-SQLAlchemy object, needed for per-request connection handling