Created
October 9, 2019 13:35
-
-
Save linkerzx/005a1a582ac4dfd1a9630eff5038e53c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jinjasql import JinjaSql | |
j = JinjaSql() | |
j.env.filters['alias_column'] = alias_column | |
j.env.filters['name_column'] = name_column | |
template = """ | |
SELECT | |
{{ columns |map('alias_column')| join(',\n') }} | |
FROM {{table_name}} a | |
{% if where != None %} | |
WHERE | |
{{where}} | |
{% endif %} | |
GROUP BY | |
{{ columns | map('name_column') | join(',\n') }} | |
""" | |
data = { | |
"table_name": 'test_02', | |
"columns":columns, | |
"where":"category = 'test'" | |
} | |
query, bind_params = j.prepare_query(template, data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment