FIQL形式の文字列を受け取り、peewee式を返す関数を作成しようとしています。
次のような FIQL 形式の URL パラメータがあるとします。
fiql_str = "name==Foo,(country==USA;city==Kansas)"
FIQL パーサーを使用すると、このオブジェクトを取り戻すことができます。
['OR', ('name', '==', 'Foo'), ['AND', ('country', '==', 'USA'), ('city', '==', 'Kansas')]]
私がやりたいのは、上記のオブジェクトを受け取り、peewee が理解できる式を作成する関数を作成することです。私はdjango & Q objectsに慣れていて、次のように式を連鎖させることができます:
fm = Q()
for mapping in mappings:
fm |= Q(subscription__approver=mapping.user)
return self.filter(fm)
私はこれを peewee のQuery Builder / Nodeで次のように模倣しようとしました:
def map_to_filter(expressions, node):
expression = expressions.pop(0)
if type(expression) == str:
if expression == "OR":
node |= map_to_filter(expressions, node)
if expression == "AND":
node &= map_to_filter(expressions, node)
elif type(expression) == tuple:
return getattr(Store, expression[0]) + expression[1] + expression[2]
elif type(expression) == list:
map_to_filter(expression, node)
return node
result = map_to_filter(expressions, peewee.Node())
しかし、私は NotImplementedError を取得しています:
/lib/python3.7/site-packages/peewee.py in __sql__(self, ctx)
616
617 def __sql__(self, ctx):
--> 618 raise NotImplementedError
619
620 @staticmethod
NotImplementedError:
そのような機能を構築することは可能ですか?それ以外の場合、これをトラブルシューティングするために利用できる他のツール/プラグインは何ですか?