| 1 |
import asyncio |
| 2 |
import aiomysql |
| 3 |
|
| 4 |
|
| 5 |
loop = asyncio.get_event_loop() |
| 6 |
|
| 7 |
|
| 8 |
@asyncio.coroutine |
| 9 |
def test_example(): |
| 10 |
pool = yield from aiomysql.create_pool( |
| 11 |
host='127.0.0.1', |
| 12 |
port=3306, |
| 13 |
user='root', |
| 14 |
password='', |
| 15 |
db='mysql', |
| 16 |
loop=loop |
| 17 |
) |
| 18 |
with (yield from pool) as conn: |
| 19 |
cur = yield from conn.cursor() |
| 20 |
yield from cur.execute("SELECT 10") |
| 21 |
# print(cur.description) |
| 22 |
(r,) = yield from cur.fetchone() |
| 23 |
assert r == 10 |
| 24 |
pool.close() |
| 25 |
yield from pool.wait_closed() |
| 26 |
|
| 27 |
|
| 28 |
loop.run_until_complete(test_example()) |