- Notifications
You must be signed in to change notification settings - Fork5
aiomysql is a library for accessing a MySQL database from the asyncio
License
sqlalchemy/aiomysql
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
aiomysql is a "driver" for accessing a MySQL databasefrom theasyncio (PEP-3156/tulip) framework. It depends on and reuses mostparts ofPyMySQL .aiomysql tries to be like awesomeaiopg library andpreserve same api, look and feel.
Internallyaiomysql is copy of PyMySQL, underlying io calls switchedto async, basicallyyield from
andasyncio.coroutine
added inproper places)). sqlalchemy support ported fromaiopg.
https://aiomysql.readthedocs.io/
https://groups.google.com/forum/#!forum/aio-libs
aiomysql based onPyMySQL , and provides same api, you just needto useawait conn.f()
oryield from conn.f()
instead of callingconn.f()
for every method.
Properties are unchanged, soconn.prop
is correct as well asconn.prop = val
.
importasyncioimportaiomysqlasyncdeftest_example(loop):pool=awaitaiomysql.create_pool(host='127.0.0.1',port=3306,user='root',password='',db='mysql',loop=loop)asyncwithpool.acquire()asconn:asyncwithconn.cursor()ascur:awaitcur.execute("SELECT 42;")print(cur.description) (r,)=awaitcur.fetchone()assertr==42pool.close()awaitpool.wait_closed()loop=asyncio.get_event_loop()loop.run_until_complete(test_example(loop))
Sqlalchemy support has been ported fromaiopg so api should be very familiarforaiopg user.:
importasyncioimportsqlalchemyassafromaiomysql.saimportcreate_enginemetadata=sa.MetaData()tbl=sa.Table('tbl',metadata,sa.Column('id',sa.Integer,primary_key=True),sa.Column('val',sa.String(255)))asyncdefgo(loop):engine=awaitcreate_engine(user='root',db='test_pymysql',host='127.0.0.1',password='',loop=loop)asyncwithengine.acquire()asconn:awaitconn.execute(tbl.insert().values(val='abc'))awaitconn.execute(tbl.insert().values(val='xyz'))asyncforrowinconn.execute(tbl.select()):print(row.id,row.val)engine.close()awaitengine.wait_closed()loop=asyncio.get_event_loop()loop.run_until_complete(go(loop))
About
aiomysql is a library for accessing a MySQL database from the asyncio
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- Python99.6%
- Makefile0.4%