Skip to content

Instantly share code, notes, and snippets.

@clrcrl
Created June 17, 2020 13:47
Show Gist options
  • Save clrcrl/99c5e995d30b5f39dd92689f07dc9955 to your computer and use it in GitHub Desktop.
Save clrcrl/99c5e995d30b5f39dd92689f07dc9955 to your computer and use it in GitHub Desktop.
{% macro clean_data(relation) %}
{%- set columns = adapter.get_columns_in_relation(relation) -%}
{% set where_clauses={
'id': 'not in (1, 2)',
'last_name': "not in ('Carroll')"
} %}
select
{% for column in columns %}
{{ column.name | lower }} {{", " if not loop.last}}
{%- endfor %}
from {{ relation }}
where
{% for column in columns %}
{% if column.name | lower in where_clauses.keys() %}
{{ "and" if not loop.first }} {{ column.name | lower }} {{ where_clauses[ column.name | lower] }}
{% endif %}
{% endfor %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment