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()
def db_session(settings: Settings = Depends(get_settings)): db = Database(settings) with db.get_session() as session: yield session