def import_data(engine, Session): session = Session() session.configure(bind=engine) try: import_from_json(session, pkg_resources.resource_stream( 'aybu.manager.data', 'manager_default_data.json')) session.flush() except: session.rollback() raise else: session.commit() finally: session.close() Session.close_all()
def import_data(config): engine = engine_from_config(config, prefix='sqlalchemy.') Session = sessionmaker(bind=engine) Base.metadata.bind = engine Base.metadata.drop_all() Base.metadata.create_all() session = Session() session.configure(bind=engine) try: import_from_json(session, pkg_resources.resource_stream( 'aybu.manager.data', 'manager_default_data.json')) session.flush() except: session.rollback() raise else: session.commit() finally: session.close() session.close_all()