Debian Codegraph @

examples/example_pool.py

raw
1 import asyncio
2 import aiomysql
3
4
5 async def test_example(loop):
6 pool = await aiomysql.create_pool(host='127.0.0.1', port=3306,
7 user='root', password='',
8 db='mysql', loop=loop)
9 async with pool.acquire() as conn:
10 async with conn.cursor() as cur:
11 await cur.execute("SELECT 42;")
12 print(cur.description)
13 (r,) = await cur.fetchone()
14 assert r == 42
15 pool.close()
16 await pool.wait_closed()
17
18
19 loop = asyncio.get_event_loop()
20 loop.run_until_complete(test_example(loop))