コード例 #1
0
async def test_pool_by_dsn(event_loop):
    """ test creation using DSN """
    pool = AsyncPool(DRIVER, dsn=DSN, loop=event_loop)
    pytest.assume(pool.is_connected() is False)
    await pool.connect()
    pytest.assume(pool.is_connected() is True)
    db = await pool.acquire()
    result, error = await db.test_connection('helloworld')
    pytest.assume(not error)
    pytest.assume(result == 'helloworld')
    user = {
        "Name": "Pradeep",
        "Company": "SCTL",
        "Address": "Mumbai",
        "Location": "RCP",
    }
    await db.set_hash("user", user)
    pytest.assume(await db.exists("user") == 1)
    result = await db.get_hash("user")
    # print(result, await db.exists("user"))
    pytest.assume(result["Name"] == "Pradeep")
    await db.delete("user")
    pytest.assume(await db.exists("user") == 0)
    await pool.close()
    assert pool.is_closed() is True
コード例 #2
0
async def test_pool_by_dsn(event_loop):
    """ test creation using DSN """
    pool = AsyncPool(DRIVER, dsn=DSN, loop=event_loop)
    pytest.assume(pool.is_connected() is False)
    await pool.connect()
    pytest.assume(pool.is_connected() is True)
    db = await pool.acquire()
    result, error = await db.test_connection('helloworld')
    pytest.assume(not error)
    pytest.assume(result == 'helloworld')
    await pool.close()
    assert pool.is_closed() is True
コード例 #3
0
async def test_pool_connect(event_loop):
    pool = AsyncPool("pg", params=PARAMS, loop=event_loop)
    pytest.assume(pool.application_name == 'Navigator')
    await pool.connect()
    pytest.assume(pool.is_connected() == True)
    db = await pool.acquire()
    pytest.assume(db.is_connected() == True)
    result = await pool.execute("SELECT 1")
    pytest.assume(result == 'SELECT 1')
    result, error = await db.test_connection()
    row = result[0]
    pytest.assume(row[0] == 1)
    await pool.release(connection=db)
コード例 #4
0
async def test_many(event_loop):
    pool = AsyncPool(DRIVER, dsn=DSN, loop=event_loop)
    pytest.assume(pool.is_connected() is False)
    await pool.connect()
    pytest.assume(pool.is_connected() is True)
    for lp in range(10000):
        print(f'Test number {lp}')
        async with await pool.acquire() as cnt:
            await cnt.ping()
            await cnt.execute("set", "Test1", "UltraTest")
            result = await cnt.get('Test1')
            pytest.assume(result == "UltraTest")
            await cnt.delete("Test1")
    print('Ending ...')
コード例 #5
0
    def __init__(self,
                 driver: str = 'pg',
                 dsn: str = '',
                 name: str = '',
                 init: Callable = None,
                 startup: Callable = None,
                 shutdown: Callable = None,
                 **kwargs):
        self.driver = driver
        if 'loop' in kwargs:
            self._loop = kwargs['loop']
            del kwargs['loop']
        if init:
            self._init = init
        if startup:
            self._startup = startup
        if shutdown:
            self._shutdown = shutdown

        if self.pool_based:
            self.conn = AsyncPool(self.driver,
                                  dsn=dsn,
                                  timeout=self.timeout,
                                  **kwargs)
        else:
            self.conn = AsyncDB(self.driver,
                                dsn=dsn,
                                timeout=self.timeout,
                                **kwargs)
        # configure connection
        self.configure()
コード例 #6
0
    def __init__(self,
                 dsn: str,
                 name: str = '',
                 init: Callable = None,
                 startup: Callable = None,
                 shutdown: Callable = None,
                 **kwargs):
        kwargs = {
            'min_size': 10,
            "server_settings": {
                'application_name': name,
                'client_min_messages': 'notice',
                'max_parallel_workers': '24',
                'jit': 'on',
                'statement_timeout': '3600000',
                'timezone': TIMEZONE
            }
        }
        if 'loop' in kwargs:
            self._loop = kwargs['loop']
            del kwargs['loop']
        if init:
            self._init = init
        if startup:
            self._startup = startup
        if shutdown:
            self._shutdown = shutdown

        self.conn = AsyncPool(self.driver,
                              dsn=dsn,
                              timeout=self.timeout,
                              **kwargs)
        # passing the configuration
        self.conn.setup_func = self.configure
コード例 #7
0
async def test_changing_app(event_loop):
    """ Change the Application Name on connect """
    args = {
        "server_settings": {
            "application_name": "Testing"
        }
    }
    p = AsyncPool("pg", params=PARAMS, loop=event_loop, **args)
    assert p.application_name == 'Testing'
コード例 #8
0
async def test_pool_by_params(event_loop):
    pool = AsyncPool("pg", params=PARAMS, loop=event_loop)
    assert pool.get_dsn() == asyncpg_url
コード例 #9
0
async def test_pool_by_dsn(event_loop):
    """ test creation using DSN """
    pool = AsyncPool("pg", dsn=asyncpg_url, loop=event_loop)
    assert pool.application_name == 'Navigator'
コード例 #10
0
async def pooler(event_loop):
    pool = AsyncPool('pg', dsn=asyncpg_url, loop=event_loop)
    await pool.connect()
    yield pool
    await pool.wait_close(gracefully=True, timeout=5)
コード例 #11
0
async def test_pool_by_params(event_loop):
    pool = AsyncPool(DRIVER, params=params, loop=event_loop)
    assert pool.get_dsn() == redis_url
コード例 #12
0
        frozen = False


loop = asyncio.new_event_loop()
loop.set_exception_handler(default_exception_handler)

params = {
    "user": "******",
    "password": "******",
    "host": "127.0.0.1",
    "port": "5432",
    "database": "navigator_dev",
    "DEBUG": True,
}

pool = AsyncPool('pg', loop=loop, params=params)
loop.run_until_complete(pool.connect())
db = loop.run_until_complete(pool.acquire())

print('Pool Connected: ', pool.is_connected())
db = loop.run_until_complete(pool.acquire())
print('Is Connected: ', db.is_connected())
loop.run_until_complete(db.test_connection())

try:
    print('CREATION of MODEL::')
    mdl = QueryUtil(**{"query_slug": "walmart_stores"})
    mdl.Meta.set_connection(db)
    result = loop.run_until_complete(mdl.fetch(raw_query=False))
    print('RESULT IS: ', result)
コード例 #13
0
ファイル: test_aredis.py プロジェクト: phenobarbital/asyncdb
#
# try:
#     client = aredis.StrictRedis(
#         connection_pool=pool
#     )
#     print(isinstance(client, aredis.StrictRedis))
#     #print(loop.run_until_complete(client.info()))
#     loop.run_until_complete(client.execute_command("set", "Test1", "UltraTest"))
#     conn = client.connection_pool._available_connections[0]
#     conn1 = pool._available_connections[0]
#     assert conn == conn1
# finally:
#     pool.disconnect()
#     loop.close()

rd = AsyncPool("asyncredis", dsn=redis_url, loop=loop)
# # rd = redisPool(dsn=redis_url, loop=loop)
loop.run_until_complete(rd.connect())


#
# # rd = AsyncDB('redis', dsn=redis_url, loop=loop)
# # loop.run_until_complete(rd.connection())
#
#
async def test_redis(pool):
    async with pool as db:
        print("Connected: {}".format(db.is_connected()))
        await db.test_connection()
        async with await pool.acquire() as conn:
            print(await conn.test_connection('TEST', 'TEST1'))
コード例 #14
0
async def test_pool_by_params(event_loop):
    pool = AsyncPool(DRIVER, params=params, loop=event_loop)
    pytest.assume(pool.is_connected() is False)
    await pool.connect()
    pytest.assume(pool.is_connected() is True)
    await pool.close()
コード例 #15
0
ファイル: test_redis.py プロジェクト: jelitox/asyncdb
loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop)
loop.set_debug(True)

logging.basicConfig(level=logging.INFO,
                    format="%(name)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)

from asyncdb import AsyncDB, AsyncPool
from asyncdb.exceptions import NoDataFound, ProviderError
from asyncdb.providers.redis import redis, redisPool

redis_url = "redis://localhost:6379/3"

rd = AsyncPool("redis", dsn=redis_url, loop=loop)
# rd = redisPool(dsn=redis_url, loop=loop)
loop.run_until_complete(rd.connect())


# rd = AsyncDB('redis', dsn=redis_url, loop=loop)
# loop.run_until_complete(rd.connection())
async def test_redis(conn):
    await conn.execute("set", "Test1", "UltraTest")
    await conn.set("Test2", "No More Test")
    if await conn.exists("Test1", "Test2"):
        value = await conn.get("Test1")
        print(value)
    await conn.setex("Test3", "Expiration Data", 10)
    await conn.persist("Test3")
    value = await conn.get("Test3")
コード例 #16
0
ファイル: test_asyncdb.py プロジェクト: phenobarbital/asyncdb
        )
        WITH (
          OIDS=FALSE
        );
        ALTER TABLE  test.stores
          OWNER TO "troc-pgdata";
"""

import asyncio

loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop)

asyncpg_url = "postgres://*****:*****@127.0.0.1:5432/navigator_dev"

pool = AsyncPool("pg", dsn=asyncpg_url, loop=loop)
loop.run_until_complete(pool.connect())
db = loop.run_until_complete(pool.acquire())
loop.run_until_complete(pool.release(connection=db.get_connection()))

print(db, type(db))

result = loop.run_until_complete(pool.execute("SELECT 1"))
print(result)


def adb():
    #loop = asyncio.get_event_loop()
    db = None
    if pool.is_connected():
        #db = asyncio.get_running_loop().run_until_complete(dbpool.acquire())