Ejemplo n.º 1
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)

    # Configure sqlalchemy engine
    engine = engine_from_config(settings, 'sqlalchemy.')

    # Create a sessionmaker
    sessionmaker = sqla_sessionmaker()
    sessionmaker.configure(bind=engine)

    # Get us a dbsession
    dbsession = sessionmaker()

    # Register said dbsession against the transaction manager
    zope.sqlalchemy.register(dbsession,
                             transaction_manager=transaction.manager)

    # Using the metadata create all objects
    Base.metadata.create_all(engine)

    with transaction.manager:
        u = User(email='*****@*****.**', credentials='testing')
        dbsession.add(u)
Ejemplo n.º 2
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)

    # Configure sqlalchemy engine
    engine = engine_from_config(settings, 'sqlalchemy.')

    # Create a sessionmaker
    sessionmaker = sqla_sessionmaker()
    sessionmaker.configure(bind=engine)

    # Get us a dbsession
    dbsession = sessionmaker()

    # Register said dbsession against the transaction manager
    zope.sqlalchemy.register(dbsession, transaction_manager=transaction.manager)

    # Using the metadata create all objects
    Base.metadata.create_all(engine)

    with transaction.manager:
        u = User(email='*****@*****.**', credentials='testing')
        dbsession.add(u)
Ejemplo n.º 3
0
 def _sessionmaker(self):
   ''' SQLAlchemy sessionmaker for the current `Thread`.
   '''
   orm_state = self.sqla_state
   if self.serial_sessions:
     sessionmaker = orm_state.sessionmaker
   else:
     sessionmaker = self._sessionmaker_raw
   if sessionmaker is None:
     sessionmaker = sqla_sessionmaker(bind=self.engine)
     self._sessionmaker_raw = sessionmaker
     orm_state.sessionmaker = sessionmaker  # pylint: disable=attribute-defined-outside-init
   return sessionmaker
Ejemplo n.º 4
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)

    # Configure sqlalchemy engine
    engine = engine_from_config(settings, 'sqlalchemy.')

    # Create a sessionmaker
    sessionmaker = sqla_sessionmaker()
    sessionmaker.configure(bind=engine)

    # Get us a dbsession
    dbsession = sessionmaker()

    # Register said dbsession against the transaction manager
    zope.sqlalchemy.register(dbsession, transaction_manager=transaction.manager)

    # Drop all tables/everything
    Base.metadata.drop_all(engine)
Ejemplo n.º 5
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)

    # Configure sqlalchemy engine
    engine = engine_from_config(settings, 'sqlalchemy.')

    # Create a sessionmaker
    sessionmaker = sqla_sessionmaker()
    sessionmaker.configure(bind=engine)

    # Get us a dbsession
    dbsession = sessionmaker()

    # Register said dbsession against the transaction manager
    zope.sqlalchemy.register(dbsession,
                             transaction_manager=transaction.manager)

    # Drop all tables/everything
    Base.metadata.drop_all(engine)
Ejemplo n.º 6
0
def build_sessionmaker(settings, prefix='sqlalchemy.'):
    engine = engine_from_config(settings, prefix)
    sessionmaker = sqla_sessionmaker()
    sessionmaker.configure(bind=engine)
    return sessionmaker