"""mysql connector for the legacy database.""" from pricing import config from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker if config.ENVIRONMENT == config.TEST_ENVIRONMENT: # For the test environment the database used is an in-memory sqlite db. # This db gets dropped immediately after the execution of the tests. _db_engine = create_engine('sqlite://') else: _db_engine = create_engine(config.AR_DB_URL, poolclass=config.POOL) # A session() instance establishes all conversations with the database # and represents a "staging zone" for all the objects loaded into the # database session object. Any change made against the objects in the # session won't be persisted into the database until you call # session.commit(). If you're not happy about the changes, you can # revert all of them back to the last commit by calling # session.rollback() # # Description taken from: # pythoncentral.io/introductory-tutorial-python-sqlalchemy/ _db_session = sessionmaker(bind=_db_engine) def get_session(): """Get a database session. Returns: callable: the encapsulated wrapper. """ return _db_session()