From 42204d449e9a98c20e2b67a4dee33cac1ad3bec1 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 1 Jun 2025 10:57:30 +0800 Subject: [PATCH] bugfix --- README.md | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 732aed9..dd01447 100755 --- a/README.md +++ b/README.md @@ -72,13 +72,40 @@ loop = asyncio.get_event_loop() pool = DBPools(dbs,loop=loop) async def testfunc(): - @pool.runSQL - def sql(db,ns,callback): - return { - "sql_string":"select * from product", - } - x = await sql('cfae',{},print) - x = await sql('aiocfae',{},print) + db = DBPools() + async with db.sqlorContext('stock') as sor: + # start a transaction + # if exception happended, all change to database will rollback + # else will commit + sql = "select * from stock where stock_num = ${stock_num}" + 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()) ```