Skip to content

Commit

Permalink
Update README.rst to avoid deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert authored Jan 7, 2025
1 parent 83aa96e commit 25fc945
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,19 @@ Properties are unchanged, so ``conn.prop`` is correct as well as
import aiomysql
async def test_example(loop):
pool = await aiomysql.create_pool(host='127.0.0.1', port=3306,
async def test_example():
async with aiomysql.create_pool(host='127.0.0.1', port=3306,
user='root', password='',
db='mysql', loop=loop)
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 42;")
print(cur.description)
(r,) = await cur.fetchone()
assert r == 42
pool.close()
await pool.wait_closed()
db='mysql') as pool:
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 42;")
print(cur.description)
(r,) = await cur.fetchone()
assert r == 42
loop = asyncio.get_event_loop()
loop.run_until_complete(test_example(loop))
asyncio.run(test_example())
Example of SQLAlchemy optional integration
Expand All @@ -83,9 +80,9 @@ for aiopg_ user.:
sa.Column('val', sa.String(255)))
async def go(loop):
async def go():
engine = await create_engine(user='root', db='test_pymysql',
host='127.0.0.1', password='', loop=loop)
host='127.0.0.1', password='')
async with engine.acquire() as conn:
await conn.execute(tbl.insert().values(val='abc'))
await conn.execute(tbl.insert().values(val='xyz'))
Expand All @@ -97,8 +94,7 @@ for aiopg_ user.:
await engine.wait_closed()
loop = asyncio.get_event_loop()
loop.run_until_complete(go(loop))
asyncio.run(go())
Requirements
Expand Down

0 comments on commit 25fc945

Please sign in to comment.