aiopg是一个使用asyncio(PEP-3156/tulip)框架开发的用来访问PostgreSQL数据库的Python开发库,封装了基于Psycopg数据库驱动程序的异步特性。
示例代码:
import asynciofrom aiopg.pool import create_pooldsn = 'dbname=jetty user=nick password=1234 host=localhost port=5432'@asyncio.coroutinedef test_select(): pool = yield from create_pool(dsn) with (yield from pool) as conn: cur = yield from conn.cursor() yield from cur.execute('SELECT 1') ret = yield from cur.fetchone() assert ret == (1,), retasyncio.get_event_loop().run_until_complete(test_select())
评论