magpie.db¶
Module Contents¶
-
magpie.db.get_db_url(username=None, password=None, db_host=None, db_port=None, db_name=None, settings=None)[source]¶
-
magpie.db.get_tm_session(session_factory, transaction_manager)[source]¶ Get a
sqlalchemy.orm.Sessioninstance backed by a transaction.This function will hook the session to the transaction manager which will take care of committing any changes.
When using pyramid_tm it will automatically be committed or aborted depending on whether an exception is raised.
When using scripts you should wrap the session in a manager yourself. For example:
import transaction engine = get_engine(settings) session_factory = get_session_factory(engine) with transaction.manager: db_session = get_tm_session(session_factory, transaction.manager)
-
magpie.db.get_db_session_from_config_ini(config_ini_path, ini_main_section_name='app:magpie_app', settings_override=None)[source]¶
-
magpie.db.run_database_migration(db_session=None) → None[source]¶ Runs db migration operations with alembic, using db session or a new engine connection.
-
magpie.db.run_database_migration_when_ready(settings, db_session=None) → None[source]¶ Runs db migration if requested by config and need from revisions.