Skip to content

Commit

Permalink
update README to python3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jettify committed Sep 2, 2016
1 parent e526483 commit 0aa221e
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,22 @@ Connection pooling ported from aiopg_ :
import aiomysql
loop = asyncio.get_event_loop()
@asyncio.coroutine
def test_example():
pool = yield from aiomysql.create_pool(host='127.0.0.1', port=3306,
user='root', password='',
db='mysql', loop=loop)
with (yield from pool) as conn:
cur = yield from conn.cursor()
yield from cur.execute("SELECT 10")
# print(cur.description)
(r,) = yield from cur.fetchone()
assert r == 10
async def test_example(loop):
pool = await 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()
yield from pool.wait_closed()
await pool.wait_closed()
loop.run_until_complete(test_example())
loop = asyncio.get_event_loop()
loop.run_until_complete(test_example(loop))
Example of SQLAlchemy optional integration
Expand All @@ -101,34 +99,35 @@ for aiopg_ user.:

.. code:: python
import asyncio
from aiomysql.sa import create_engine
import sqlalchemy as sa
import asyncio
import sqlalchemy as sa
from aiomysql.sa import create_engine
metadata = sa.MetaData()
metadata = sa.MetaData()
tbl = sa.Table('tbl', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('val', sa.String(255)))
tbl = sa.Table('tbl', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('val', sa.String(255)))
@asyncio.coroutine
def go():
engine = yield from create_engine(user='root',
db='aiomysql',
host='127.0.0.1',
password='')
async def go(loop):
engine = await create_engine(user='root', db='test_pymysql',
host='127.0.0.1', password='', loop=loop)
async with engine.acquire() as conn:
await conn.execute(tbl.insert().values(val='abc'))
await conn.execute(tbl.insert().values(val='xyz'))
with (yield from engine) as conn:
yield from conn.execute(tbl.insert().values(val='abc'))
async for row in conn.execute(tbl.select()):
print(row.id, row.val)
res = yield from conn.execute(tbl.select())
for row in res:
print(row.id, row.val)
engine.close()
await engine.wait_closed()
asyncio.get_event_loop().run_until_complete(go())
loop = asyncio.get_event_loop()
loop.run_until_complete(go(loop))
Requirements
Expand Down

0 comments on commit 0aa221e

Please sign in to comment.