Пример #1
0
async def DummyDatabaseConfigurationFactory(key, dbconfig, app):
    dss = DummyStorage()
    dbc = {}
    dbc['database_name'] = key
    db = GuillotinaDB(dss, **dbc)
    await db.initialize()
    return Database(key, db)
Пример #2
0
async def _PGConfigurationFactory(key,
                                  dbconfig,
                                  loop=None,
                                  storage_factory=PostgresqlStorage):
    if isinstance(dbconfig['dsn'], str):
        dsn = dbconfig['dsn']
    else:
        dsn = _convert_dsn(dbconfig['dsn'])

    partition_object = None
    if 'partition' in dbconfig:
        partition_object = resolve_dotted_name(dbconfig['partition'])

    dbconfig.update({
        'dsn': dsn,
        'name': key,
        'partition': partition_object,
        'pool_size': dbconfig.get('pool_size', 13)
    })

    connection_options = _get_connection_options(dbconfig)

    aps = storage_factory(**dbconfig)
    if loop is not None:
        await aps.initialize(loop=loop, **connection_options)
    else:
        await aps.initialize(**connection_options)
    db = Database(key, aps)
    await db.initialize()
    return db
Пример #3
0
async def _PGConfigurationFactory(key, dbconfig, loop=None, storage_factory=PostgresqlStorage):
    if isinstance(dbconfig["dsn"], str):
        dsn = dbconfig["dsn"]
    else:
        dsn = _convert_dsn(dbconfig["dsn"])

    partition_object = None
    if "partition" in dbconfig:
        partition_object = resolve_dotted_name(dbconfig["partition"])

    dbconfig.update(
        {"dsn": dsn, "name": key, "partition": partition_object, "pool_size": dbconfig.get("pool_size", 13)}
    )

    connection_options = _get_connection_options(dbconfig)

    aps = storage_factory(**dbconfig)
    if loop is not None:
        await aps.initialize(loop=loop, **connection_options)
    else:
        await aps.initialize(**connection_options)

    if "transaction_manager" in dbconfig:
        transaction_manager = resolve_dotted_name(dbconfig["transaction_manager"])
    else:
        transaction_manager = TransactionManager
    db = Database(key, aps, transaction_manager)
    await db.initialize()
    return db
Пример #4
0
async def CouchbaseDatabaseConfigurationFactory(key, dbconfig, loop=None):
    dss = RocksdbStorage(**dbconfig)
    if loop is not None:
        await dss.initialize(loop=loop)
    else:
        await dss.initialize()

    db = Database(key, dss)
    await db.initialize()
    return db
Пример #5
0
async def _PGConfigurationFactory(key,
                                  dbconfig,
                                  app,
                                  storage_factory=PostgresqlStorage):
    # b/w compat, we don't use this for storage options anymore
    config = dbconfig.get('configuration', {})

    if isinstance(dbconfig['dsn'], str):
        dsn = dbconfig['dsn']
    else:
        dsn = "{scheme}://{user}:{password}@{host}:{port}/{dbname}".format(
            **dbconfig['dsn'])

    partition_object = None
    if 'partition' in dbconfig:
        partition_object = resolve_dotted_name(dbconfig['partition'])

    dbconfig.update({
        'dsn':
        dsn,
        'name':
        key,
        'partition':
        partition_object,
        'pool_size':
        dbconfig.get('pool_size', config.get('pool_size', 13))
    })

    connection_options = {}
    if 'ssl' in dbconfig:
        import ssl
        ssl_config = dbconfig['ssl']
        ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        ssl_context.load_verify_locations(ssl_config['ca'])
        ssl_context.load_cert_chain(ssl_config['cert'],
                                    keyfile=ssl_config['key'])
        connection_options['ssl'] = ssl_context

    aps = storage_factory(**dbconfig)
    if app is not None:
        await aps.initialize(loop=app.loop, **connection_options)
    else:
        await aps.initialize(**connection_options)
    dbc = {}
    dbc['database_name'] = key
    db = GuillotinaDB(aps, **dbc)
    await db.initialize()
    return Database(key, db)
Пример #6
0
async def DatabaseConfigurationFactory(key, dbconfig, app):
    config = dbconfig.get('configuration', {})
    dsn = "{scheme}://{user}:{password}@{host}:{port}/{dbname}".format(
        **dbconfig['dsn'])  # noqa
    partition_object = None
    if 'partition' in dbconfig:
        partition_object = resolve_dotted_name(dbconfig['partition'])
    pool_size = config.get('pool_size', 100)
    aps = APgStorage(dsn=dsn,
                     partition=partition_object,
                     name=key,
                     pool_size=pool_size)
    if app is not None:
        await aps.initialize(loop=app.loop)
    else:
        await aps.initialize()
    dbc = {}
    dbc['database_name'] = key
    db = GuillotinaDB(aps, **dbc)
    await db.initialize()
    return Database(key, db)
Пример #7
0
async def DummyDatabaseConfigurationFactory(key, dbconfig, loop=None):
    dss = DummyStorage()
    db = Database(key, dss)
    await db.initialize()
    return db
Пример #8
0
async def DummyFileDatabaseConfigurationFactory(key, dbconfig, loop=None):
    dss = DummyFileStorage(dbconfig.get('filename', 'g.db'))
    db = Database(key, dss)
    await db.initialize()
    return db