badass

Crates.iobadass
lib.rsbadass
version0.1.2
sourcesrc
created_at2024-03-22 10:55:37.220832
updated_at2024-03-22 18:42:59.88691
descriptionbadass is a cli tool inspired by dbt and airflow
homepagehttps://github.com/timvw/badass
repositoryhttps://github.com/timvw/badass
max_upload_size
id1182520
size82,987
Tim Van Wassenhove (timvw)

documentation

README

BADASS

Badass is a CLI tool inspired by DBT and Airflow. Mainly a playground for me to become more familiar with Rust.

Configuration

Badass uses config-rs to search for a badass config (.toml, .json, .yaml or .ini) in the current workin directory. It is also possible to override settings with an environment variable (prefixed with BADASS_)

BADASS_output_compiled=/tmp/compiled badass settings
The settings are: 

Settings {
    models: Models {
        location: "./demo/models",
    },
    output: Output {
        compiled: "/tmp/compiled",
        materialized: "./target/materialized",
    },
    query_engine: QueryEngine {
        params: "host=localhost user=tim",
    },
}

Features

Compile SQL templates

badass compile

We leverage minijinja to generate SQL files.

{% set payment_methods = ["bank_transfer", "credit_card", "gift_card"] %}
select
    order_id,
    {%- for payment_method in payment_methods %}
    sum(case when payment_method = '{{payment_method}}' then amount end) as {{payment_method}}_amount,
    {%- endfor %}
    sum(amount) as total_amount
from app_data.payments
group by 1

Is compiled into the following:

select
    order_id,
    sum(case when payment_method = 'bank_transfer' then amount end) as bank_transfer_amount,
    sum(case when payment_method = 'credit_card' then amount end) as credit_card_amount,
    sum(case when payment_method = 'gift_card' then amount end) as gift_card_amount,
    sum(amount) as total_amount
from app_data.payments
group by 1

View (compiled) SQL template query results

badass show demo
.------------------------.
| Tim   | Van Wassenhove |
| Tiebe | Van Wassenhove |
| Amber | Van Wassenhove |
| Evy   | Penninckx      |
'------------------------'

Materialize SQL templates

badass materialize

Use the (compiled) SQL templates to build database artifacts (tables, views, ...)

Currently we only render CTAS, eg:

SELECT * FROM foo

Becomes

CREATE TABLE xxx AS SELECT * FROM foo
Commit count: 37

cargo fmt