示例#1
0
    return sqlalchemy.create_engine(url, **options)


def configure_session(uri):
    """
    (Re)configure the session by closing the existing session if it exists and
    loading the current configuration for use by future sessions.
    """
    global session_factory, session
    session.remove()
    session_factory.configure(bind=create_engine())


# Reconfigure the session if database configuration is updated.
settings.on_update(configure_session, 'DATABASE_URI')

# Sessions are automatically created where needed and are scoped by thread.
session_factory = SessionFactory()

#: Global scoped :class:`sqlalchemy.orm.session.Session` instance. Use this
#: for all database communication, except for querying models. For the latter,
#: each model has a `query` property that is a
#: :class:`sqlalchemy.orm.query.Query` object against the model and the
#: current `Session` when called.
session = scoped_session(session_factory)

#: Base class to use for our models.
Base = declarative_base()
Base.query = session.query_property()
示例#2
0
    return sqlalchemy.create_engine(url, **options)


def configure_session(uri):
    """
    (Re)configure the session by closing the existing session if it exists and
    loading the current configuration for use by future sessions.
    """
    global session_factory, session
    session.remove()
    session_factory.configure(bind=create_engine())


# Reconfigure the session if database configuration is updated.
settings.on_update(configure_session, 'DATABASE_GB_URI')


# Sessions are automatically created where needed and are scoped by thread.
session_factory = SessionFactory()

#: Global scoped :class:`sqlalchemy.orm.session.Session` instance. Use this
#: for all database communication, except for querying models. For the latter,
#: each model has a `query` property that is a
#: :class:`sqlalchemy.orm.query.Query` object against the model and the
#: current `Session` when called.
session = scoped_session(session_factory)


#: Base class to use for our models.
Base = declarative_base()
示例#3
0
        self.configure(settings.REDIS_URI)

    def configure(self, uri):
        """
        Configure the client with a new connectionpool for the given URI.
        """
        if uri is None:
            import mockredis
            self._wrapped = mockredis.MockRedis(strict=True)
        else:
            self._wrapped = redis.StrictRedis.from_url(uri,
                                                       decode_responses=True,
                                                       encoding='utf-8')


def configure_client(uri):
    """
    (Re)configure the client with the given URI.
    """
    global client
    client.configure(uri)


# Reconfigure the client if configuration is updated.
settings.on_update(configure_client, 'REDIS_URI')


#: Global :class:`LazyClient` instance. Use this for all communication with
#: Redis.
client = LazyClient()