| 1 |
import asyncio |
| 2 |
import aiomysql |
| 3 |
|
| 4 |
|
| 5 |
async def test_example(loop): |
| 6 |
conn = await aiomysql.connect(host='127.0.0.1', port=3306, |
| 7 |
user='root', password='', db='mysql', |
| 8 |
loop=loop) |
| 9 |
sql = "SELECT 1 `id`, JSON_OBJECT('key1', 1, 'key2', 'abc') obj" |
| 10 |
async with conn.cursor(aiomysql.cursors.DeserializationCursor, |
| 11 |
aiomysql.cursors.DictCursor) as cur: |
| 12 |
await cur.execute(sql) |
| 13 |
print(cur.description) |
| 14 |
r = await cur.fetchall() |
| 15 |
print(r) |
| 16 |
conn.close() |
| 17 |
|
| 18 |
|
| 19 |
loop = asyncio.get_event_loop() |
| 20 |
loop.run_until_complete(test_example(loop)) |