コード例 #1
0
def sqlengine(request, config):
    engine = create_engine(config.DATABASE_URL)
    session.configure(bind=engine)
    Model.metadata.create_all(engine)

    def teardown():
        Model.metadata.drop_all(engine)

    request.addfinalizer(teardown)
    return engine
コード例 #2
0
def dbtransaction(request, sqlengine):
    connection = sqlengine.connect()
    transaction = connection.begin()
    session.configure(bind=connection)

    def teardown():
        transaction.rollback()
        connection.close()
        session.remove()

    request.addfinalizer(teardown)
    return session