67 lines
1.4 KiB
Plaintext
67 lines
1.4 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
|
|
|
|
debug_params('get_llmcatelog', ns)
|
|
if not ns.get('page'):
|
|
ns['page'] = 1
|
|
if not ns.get('sort'):
|
|
|
|
|
|
ns['sort'] = ["name"]
|
|
|
|
|
|
|
|
sql = '''select * from llmcatelog where 1=1 [[filterstr]]'''
|
|
|
|
filterjson = params_kw.get('data_filter')
|
|
fields_str=r'''[
|
|
{
|
|
"name": "id",
|
|
"title": "id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "name",
|
|
"title": "类型名",
|
|
"type": "str",
|
|
"length": 100
|
|
},
|
|
{
|
|
"name": "description",
|
|
"title": "类型说明",
|
|
"type": "text"
|
|
}
|
|
]'''
|
|
ori_fields = json.loads(fields_str)
|
|
if not filterjson:
|
|
fields = [ f['name'] for f in ori_fields ]
|
|
filterjson = default_filterjson(fields, ns)
|
|
filterdic = ns.copy()
|
|
filterdic['filterstr'] = ''
|
|
filterdic['userorgid'] = '${userorgid}$'
|
|
filterdic['userid'] = '${userid}$'
|
|
if filterjson:
|
|
dbf = DBFilter(filterjson)
|
|
conds = dbf.gen(ns)
|
|
if conds:
|
|
ns.update(dbf.consts)
|
|
conds = f' and {conds}'
|
|
filterdic['filterstr'] = conds
|
|
ac = ArgsConvert('[[', ']]')
|
|
vars = ac.findAllVariables(sql)
|
|
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
|
|
filterdic.update(NameSpace)
|
|
sql = ac.convert(sql, filterdic)
|
|
|
|
debug(f'sql({len(sql)}ch): {sql[:200]}')
|
|
db = DBPools()
|
|
dbname = get_module_dbname('llm')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.sqlPaging(sql, ns)
|
|
return r
|
|
return {
|
|
"total":0,
|
|
"rows":[]
|
|
} |