ns = params_kw.copy() if not ns.get('page'): ns['page'] = 1 if not ns.get('sort'): ns['sort'] = ['prodtypeid', 'productid'] sql = '''select a.*, b.name as discountid_text, c.name as prodtypeid_text, d.product_name as productid_text from (select * from discount_detail where 1=1 [[filterstr]]) a left join (select id, name from discount) b on a.discountid = b.id left join (select id, name from product_category) c on a.prodtypeid = c.id left join (select id, product_name from product) d on a.productid = d.id''' fields = ['discountid', 'prodtypeid', 'productid', 'discount'] filterjson = default_filterjson(fields, ns) filterdic = ns.copy() filterdic['filterstr'] = '' 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('discount') async with db.sqlorContext(dbname) as sor: r = await sor.sqlPaging(sql, ns) return r return { "total": 0, "rows": [] }