aiopg是一个使用asycio(PEP-3156/tulip)框架开发的用来访问PostgreSQL数据库的Pytho开发库,封装了基于Psycopg数据库驱动程序的异步特性。
示例代码:
import asyciofrom aiopg.pool import create_poolds = 'dbame=jetty user=ick password=1234 host=localhost port=5432'@asycio.coroutiedef test_select(): pool = yield from create_pool(ds) with (yield from pool) as co: cur = yield from co.cursor() yield from cur.execute('SELECT 1') ret = yield from cur.fetchoe() assert ret == (1,), retasycio.get_evet_loop().ru_util_complete(test_select())
评论