sqlor/test/test.py

53 lines
1.2 KiB
Python
Raw Normal View History

2019-05-14 10:47:28 +08:00
import asyncio
from sqlor.dbpools import DBPools
dbs={
"aiocfae":{
"driver":"aiomysql",
"async_mode":True,
"coding":"utf8",
"dbname":"cfae",
"kwargs":{
"user":"test",
"db":"cfae",
"password":"test123",
"host":"localhost"
}
},
"cfae":{
"driver":"mysql.connector",
"coding":"utf8",
"dbname":"cfae",
"kwargs":{
"user":"test",
"db":"cfae",
"password":"test123",
"host":"localhost"
}
}
}
loop = asyncio.get_event_loop()
pool = DBPools(dbs,loop=loop)
2019-05-14 11:20:28 +08:00
async def testfunc1():
2019-05-14 10:47:28 +08:00
@pool.runSQL
def sql(db,ns,callback):
return {
"sql_string":"select * from product",
}
x = await sql('cfae',{},print)
2019-05-14 11:20:28 +08:00
async def testfunc2():
@pool.runSQLResultFields
def sql(db,NS):
return {
"sql_string":"select * from product",
}
x = await sql('cfae',{})
print(x)
loop.run_until_complete(testfunc1())
loop.run_until_complete(testfunc2())