Hi all,

based on the successful progress with my previous topic "Using BakedQuery 
with joined subqueries" (thanks again Mike!) I have the next question.

For some of my queries conditions logic is generated based on certain 
parameters. For example, I have a JSONB field that contains custom fields 
from the user. I have then "saved searches" defined by users to search on 
the custom field.
Now based on the "saved search ID" my function will generate a query.

The logic roughly is:

def generate_saved_search_query(saved_search_id):
   conditions = self.get_saved_search_conditions(saved_search_id)
   
   for condition in conditions:
       query = query.filter(condition)   

the 'generate_saved_search_query' function is idempotent for any parameter 
value. Searching for any particular saved_search_id occurs frequently => it 
makes sense to cache the query.

The question is - how can I used BakedQuery with this setup? From the 
source I can guess I should use add_criteria / with_criteria, but in the 
unit tests / documentation I could not find an example of doing so with the 
function parameter values.

Thank you for any help,
Anton

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to