aicode/kdb/sqlor.py
2025-12-05 17:50:39 +08:00

33 lines
1.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from sqlor.dbpools import DBPools
from ahserver.serverenv import ServerEnv
# 假设当前模块名称为"mymodule"
async def subcoro(sor, pid):
sql = "select * from appcoodes_kw where parentid=${pid}$"
r = await sor.sqlExe(sql, {'pid': pid})
return r
sor.R()
sor.sqlExe() 的select语句
如果ns中有page'属性,返回数据格式如下
{
"total" # 查询结果总记录数
"rows": page指定的页数据 缺省每页返回80条记录pagerows属性可设置每页记录数
}
否则返回全部记录的数组
"""
async def sqlor_op():
db = DBPools()
env = ServerEnv()
dbname = env.get_module_dbname()
async with db.sqlorContext(dbname) as sor:
# 事务中如果代码或sql失败全部滚回正常结束自动提交
await sor.C('user', {'id':'yuewfiuwe', 'username':'john'})
# 添加数据表“user”数据
await sor.D('user', {'id': 'yuewfiuwe'})
# await sor.U('user', {'id', 'email':'test@abc.com'})
# await sor.R('user', {'id': 'yuewfiuwe'})
return subcoro(sor, 'test_data')