I have two tables,
class Values(db.Model):
__tablename__ = 'attribute_values'
id = db.Column(db.Integer, primary_key=True)
attribute = db.Column(db.Integer, ForeignKey('attributes.id'), primary_key=True)
value = db.Column(JSON)
class Attributes(db.Model):
__tablename__ = 'attributes'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Text)
user_attribute = db.relationship(Values, backref='attributes', primaryjoin=id == Values.attribute)
where values has attribute_id(foreign key) and value which is JSON.
Now i will get random filters like, emails.type == "work"
, (emails.type == "work") and (emails.type == "home")
could be as nested as this one ((usertype !== "Employee") and (not ((emails.value LIKE "%example.com%") OR (emails.value LIKE "%example.org%")))) and ((usertype !== "Employee") and (not ((emails.value LIKE "%example.com%") OR (emails.value LIKE "%example.org%"))))
in all of above examples, emails
is attribute in attributes table, where in values table i will have {'type':'home'}
. Where ever (.)operator that means it is json.
even ```>,<,<=,>=" are possiblities.
How can i create sqlalchemy queries with these queries dynamically