Example #1
0
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
Example #2
0
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
Example #3
0
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)
Example #4
0
    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
Example #5
0
def new_db_session():
    return versioned_session(Session(autoflush=True, autocommit=False), Transaction, HasRevisions)