18 lines
777 B
Plaintext

ns = params_kw.copy()
id = ns.get('id')
kb_id = ns.get('kb_id', '')
db = DBPools()
dbname = get_module_dbname('rag')
async with db.sqlorContext(dbname) as sor:
if not id:
recs = await sor.sqlExe(
"SELECT id, '' as parentid, content as label FROM document_chunks WHERE kb_id=${kb_id}$ AND chunk_type='directory' AND (description IS NULL OR description='') ORDER BY content",
{"kb_id": kb_id})
return [dict(r) for r in recs]
else:
recs = await sor.sqlExe(
"SELECT id, description as parentid, content as label FROM document_chunks WHERE kb_id=${kb_id}$ AND chunk_type='directory' AND description=${id}$ ORDER BY content",
{"kb_id": kb_id, "id": id})
return [dict(r) for r in recs]
return []