JinjaSQL dynamic templates
I am using JinjaSQL to create dynamic SQL queries for filtering on a database. I want the filters to be modular, such that creating new filters are easy.
I want to insert the filters by inserting an appropriate template into a template. For example:
template = 'SELECT * FROM table WHERE {{ filter | sqlsafe }}' filter = '> {{ date_from }}' data = {'filter': filter, 'date_from': 20200101} query, params = prepare_query(template, data)
What I want is:
query = 'SELECT * FROM table WHERE date > %s' params = [20200101]
What I get is:
query = 'SELECT * FROM table WHERE date > {{ date_from }}' params = []
I guess I could fix this by simply running prepare_query
again, but is there a better way to do this?