示例#1
0
def db_session(db: Database):
    with db.get_session() as session:
        try:
            yield session
        finally:
            session.rollback()
            for table in reversed(Base.metadata.sorted_tables):
                session.execute(table.delete())
            session.commit()
            session.close()
示例#2
0
def db_session(settings: Settings = Depends(get_settings)):
    db = Database(settings)
    with db.get_session() as session:
        yield session