ns = params_kw.copy() debug(f'get_bid_chapters.dspy:{ns=}') if not ns.get('page'): ns['page'] = 1 if not ns.get('sort'): ns['sort'] = json.loads('["order_no", "chapter_no"]') sql = '''select a.*, b.status_text, c.section_text from (select * from bid_chapters where 1=1 [[filterstr]]) a left join (select k as status, v as status_text from appcodes_kv where parentid='bid_chapter_status') b on a.status = b.status left join (select k as section, v as section_text from appcodes_kv where parentid='bid_scoring_section') c on a.section = c.section''' filterjson = json.loads('{"AND": [{"field": "project_id", "op": "=", "var": "project_id"}, {"field": "status", "op": "=", "var": "status_input"}, {"field": "title", "op": "LIKE", "var": "title_input"}]}') 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=}') db = DBPools() dbname = get_module_dbname('pipeline_bidding') async with db.sqlorContext(dbname) as sor: r = await sor.sqlPaging(sql, ns) return r return { "total":0, "rows":[] }