-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Hi, I'm trying to parse string boolean SQL syntax into an SQLalchemy filter and this tool is perfect. I just discovered this today and would solve most of my problems. However, it does not appear to handle attributes that come from different classes. Could we add this ability? filter only accepts a single DataModelClass.
Let's say I have two ModelClasses, Sample, and Design, defined inside a python module, datadb, that I import. Sample has an attribute called paramA, and Design has an attribute called paramB
import datadb
s = datadb.Sample()
s.paramA
d = datadb.Design()
d.paramB
How would I parse the SQL string "paramA < 10 and paramB = 4" and convert it into the equivalent filter
"session.query().filter(datadb.Sample.paramA < 10, datadb.Design.paramB==4)"
I'd like to do be able to pass in a list of ModelClasses, a la,
sql = "paramA < 10 and paramB = 4"
parsed = parse_boolean_search(sql)
sap = parsed.filter( [datadb.Sample, datadb.Design] )
or
sap = parsed.filter( datadb.Sample, datadb.Design )
or pass in an entire module with ModuleClasses defined inside it
sql = "Sample.paramA < 10 and Design.paramB = 4"
parsed = parse_boolean_search(sql)
sap = parsed.filter( datadb )
It loops over all input classes it finds, and then if it can't match an attribute name to any of classes, it returns a
BooleanSearchException: Table X does not have a field named Y.
I think this functionality would greatly enhance this code. Would this be possible? @lingthio