0

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

Mohan
  • 97
  • 1
  • 6
  • Does this answer your question? [SQLALchemy dynamic filter\_by](https://stackoverflow.com/questions/29885879/sqlalchemy-dynamic-filter-by) – metatoaster Sep 15 '20 at 06:39
  • It would have worked if conditions were simple – Mohan Sep 15 '20 at 06:52
  • You would need to provide additional code/data, e.g. how are those queries being represented in e.g. JSON. Also, you did mention operator, which can be constructed using the functions provided by the [`operator`](https://docs.python.org/3/library/operator.html) module. – metatoaster Sep 15 '20 at 10:37

0 Answers0