From fae798e1839eb712efd3f43c7ee6e664021dea4d Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 15 May 2024 11:40:54 +0800 Subject: [PATCH] bugfix --- sqlor/filter.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/sqlor/filter.py b/sqlor/filter.py index cecfb51..e41c7e6 100755 --- a/sqlor/filter.py +++ b/sqlor/filter.py @@ -34,6 +34,25 @@ except: import json class DBFilter(object): + operators = [ + "=", + "!=", + "IN", + "NOT IN", + ">", + ">=", + "<", + "<=", + "IS NULL", + "IS NOT NULL", + "LIKE", + "NOT LIKE" + ] + logic = [ + "AND", + "OR", + "NOT" + ] def __init__(self,filterjson): if isinstance(filterjson, str): filterjson = json.loads(filterjson) @@ -103,9 +122,12 @@ class DBFilter(object): keys = fj.keys() assert 'field' in keys assert 'op' in keys - assert 'const' in keys or 'var' in keys - op = fj.get('op') - assert op in ['=','<>','>','<','>=','<=','in','not in'] + assert 'const' in keys or 'var' in keys or fj['op'].upper() in ['IS NULL', 'IS NOT NULL'] + op = fj.get('op').upper() + assert op in self.operators + + if op in ['IS NULL', 'IS NOT NULL']: + return f'{fj['field']} {op}' var = fj.get('var') if var and not var in ns.keys(): @@ -128,6 +150,11 @@ def default_filterjson(fields: list, ns: dict): 'op':'=', 'var':k } for k in ns.keys() if k in fields ] + print(f'default_filterjson():{c=}') + if len(c) < 1: + return None + if len(c) < 2: + return c[0] return { 'AND':c }