コード例 #1
0
ファイル: __init__.py プロジェクト: asidev/aybu-manager
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()
コード例 #2
0
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()