Попробуйте так
class DB:
def __init__(self, config: dict):
self.config = config
self._pool = None
async def get_pool(self):
return self._pool
async def create_pool(self):
self._pool = await asyncpg.create_pool(**self.config)
async def select(self):
async with self._pool.acquire() as conn:
print(await conn.fetch('''SELECT * FROM names'''))
async def select(pool):
async with pool.acquire() as conn:
print(await conn.fetch('''SELECT * FROM names'''))
db = DB(data)
async def main():
await db.create_pool()
await db.select()
pool = await db.get_pool()
await select(pool)
asyncio.run(main())