daranzolin / sqltargets

targets extension for SQL queries
https://daranzolin.github.io/sqltargets/
Other
34 stars 1 forks source link

Allow 'Jinja' like functionality in sql queries #14

Closed daranzolin closed 1 month ago

daranzolin commented 1 month ago

Jinja:

{% set payment_methods = ['credit_card', 'coupon', 'bank_transfer', 'gift_card'] %}

...
        {% for payment_method in payment_methods -%}
        sum(case when payment_method = '{{ payment_method }}' then amount else 0 end) as {{ payment_method }}_amount,
        {% endfor -%}
...

glue:

payment_methods <- c('credit_card', 'coupon', 'bank_transfer', 'gift_card')
glue("sum(case when payment_method = '{payment_methods}' then amount else 0 end as {payment_methods}_amount,")
daranzolin commented 1 month ago

Think this could work smoothly with the jinjar package: https://github.com/davidchall/jinjar