def db_session(request): # engine = create_engine('sqlite:///test.db') engine = create_engine('sqlite://') Base.metadata.create_all(engine) session = versioned_session(sessionmaker()(bind=engine), MonkeyRevision, HasRevisions) return session
def new_db_session(): """ Create a new session. Most of the time you should be using session_scope() instead, since it handles cleanup properly. Sometimes you still need to use this function directly because of how context managers require all code using the created variable to be in a block; test setup is one example. Returns ------- sqlalchemy.orm.session.Session The created session. """ return versioned_session(Session(autoflush=True, autocommit=False), Transaction, HasRevisions)
def __init__(self, versioned=True, ignore_soft_deletes=True, namespace_id=None): # TODO: support limiting on namespaces # TODO this uses our global engine here :( from inbox.server.models.ignition import engine args = dict(bind=engine, autoflush=True, autocommit=False) self.ignore_soft_deletes = ignore_soft_deletes if ignore_soft_deletes: args['query_cls'] = InboxQuery sqlalchemy_session = Session(**args) if versioned: from inbox.server.models.tables.base import (Transaction, HasRevisions) self._session = versioned_session( sqlalchemy_session, Transaction, HasRevisions) else: self._session = sqlalchemy_session
def new_db_session(): return versioned_session(Session(autoflush=True, autocommit=False), Transaction, HasRevisions)