I’m trying to add a persistent SQL where clause in SQLalchimy.
Basically I have a table containing a specific field, and I want all my request to add a where clause, so this field matches a clause.
For instance, if my request is
session.query( MyTable ).all()
I’d like the generated request to be as such :
SELECT * FROM Table WHERE specific_field = 'some_value';
Is there a way of doing this without adding a filter to each request ?
Thanks in advance.
If you add:
I’m not sure what you mean by: ‘without adding a filter to each request.’ My guess is that you don’t want to filter the request client-side. The generated SQL for this should look a lot like what you’re asking for; the
dbengine.echo = Truebit will show you the SQL that’s generated.Update based on OP comment:
If you really want all queries to have a filter, then a simple (but in my opinion not so pretty) way would be to add your own query method:
After that, you can just call (for example):