bugfix
This commit is contained in:
parent
ff670d7bd0
commit
42204d449e
41
README.md
41
README.md
@ -72,13 +72,40 @@ loop = asyncio.get_event_loop()
|
|||||||
pool = DBPools(dbs,loop=loop)
|
pool = DBPools(dbs,loop=loop)
|
||||||
|
|
||||||
async def testfunc():
|
async def testfunc():
|
||||||
@pool.runSQL
|
db = DBPools()
|
||||||
def sql(db,ns,callback):
|
async with db.sqlorContext('stock') as sor:
|
||||||
return {
|
# start a transaction
|
||||||
"sql_string":"select * from product",
|
# if exception happended, all change to database will rollback
|
||||||
}
|
# else will commit
|
||||||
x = await sql('cfae',{},print)
|
sql = "select * from stock where stock_num = ${stock_num}"
|
||||||
x = await sql('aiocfae',{},print)
|
recs = await sor.sqlExe(sql, {'stock_num':'688888'})
|
||||||
|
# return a list of DictObject instance
|
||||||
|
sql1 = "select * from stock"
|
||||||
|
recs = await sor.sqlPaging(sql, {'pagerows':50, 'page':1, 'sort':'stock_id'})
|
||||||
|
# return a dictionary {
|
||||||
|
# 'total': return all reocords count.
|
||||||
|
# 'rows': list of DictObject instance
|
||||||
|
# }
|
||||||
|
ns = {'id':'666667'} # filters dictionary, find all records which id = '666667'
|
||||||
|
recs = await sor.R('stock', ns)
|
||||||
|
# recs is a list of data in DictObject instance
|
||||||
|
ns = {'pagerows': 50, 'page':1, 'sort':stock_id'}
|
||||||
|
# find all record in table 'stock', return page 1 data which 50 max records
|
||||||
|
dic = await sor.R('stock', ns)
|
||||||
|
# return a dictionary {
|
||||||
|
# 'total': return all reocords count.
|
||||||
|
# 'rows': list of DictObject instance
|
||||||
|
# }
|
||||||
|
await sor.C('stock', {
|
||||||
|
'stock_id': '111111',
|
||||||
|
...
|
||||||
|
})
|
||||||
|
# add a record to 'stock' table
|
||||||
|
await sor.D('stock', {'stock_id':'111111'})
|
||||||
|
# delete a record in 'stock' table which stock_id = '111111'
|
||||||
|
await sor.U('stock', {'stock_id':'111111', 'name':'new_name'})
|
||||||
|
# update name field's value to 'new_name' which stock_id = '111111'
|
||||||
|
|
||||||
|
|
||||||
loop.run_until_complete(testfunc())
|
loop.run_until_complete(testfunc())
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user