long2ice / asynch

An asyncio ClickHouse Python Driver with native (TCP) interface support.
https://github.com/long2ice/asynch
Apache License 2.0
186 stars 43 forks source link

Connection pool with predefined connections #3

Closed ghuname closed 3 years ago

ghuname commented 3 years ago

Let's say that I have cluster of 6 nodes. I would like to create a connection pool with 6 connections, one per each node.

Can I implement such behavior with asynch.create_pool()?

long2ice commented 3 years ago

current not support

ghuname commented 3 years ago

In example you have provided:

async def use_pool():
    pool = await asynch.create_pool()
    async with pool.acquire() as conn:
        async with conn.cursor() as cursor:
            await cursor.execute("SELECT 1")
            ret = cursor.fetchone()
            assert ret == (1,)
    pool.close()
    await pool.wait_closed()

where connection parameters should be specified (host, port, database...)?

If I understood correctly, I should create a global pool object and afterwards, whenever I want to query database, I should use:

async with pool.acquire() as conn:
        async with conn.cursor() as cursor:
            await cursor.execute("SELECT 1")
            ret = cursor.fetchone()

Can you please confirm?

long2ice commented 3 years ago

params pass in create_pool, the example use default params

ghuname commented 3 years ago

Maybe you should update the example.