Skip to content

Commit

Permalink
Merge pull request #86 from JorgenG/use-print-for-outputting-codegen
Browse files Browse the repository at this point in the history
Use print for outputting codegen
  • Loading branch information
joellabes authored Nov 27, 2023
2 parents af12570 + 536246d commit e8b5a02
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 5 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ dispatch:

# dbt-codegen v0.8.0

# Unreleased
## Breaking changes
## New features
## Quality of life
- Now uses `print` instead of `log` to output the generated text into the console. This enables you to invoke dbt with the `--quiet` flag and directly pipe the codegen output into a new file, ending up with valid yaml

## Under the hood
## Contributors:
- [@JorgenG](https://github.com/JorgenG) (#86)

# dbt-codegen v0.7.0

## 🚨 Breaking change
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ the database to your source definition
* `include_schema` (optional, default=False): Whether you want to add
the schema to your source definition

### Outputting to a file
If you use the `dbt run-operation` approach it is possible to output directly to a file by piping the output to a new file and using the `--quiet` CLI flag:

```
dbt --quiet run-operation generate_model_yaml --args '{"model_name": "stg_jaffle_shop__orders"}' > models/staging/jaffle_shop/stg_jaffle_shop__orders.yml
```

### Usage:
1. Copy the macro into a statement tab in the dbt Cloud IDE, or into an analysis file, and compile your code

Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'codegen'
version: '0.5.0'

require-dbt-version: [">=1.0.0", "<2.0.0"]
require-dbt-version: [">=1.1.0", "<2.0.0"]
config-version: 2

target-path: "target"
Expand Down
2 changes: 1 addition & 1 deletion macros/generate_base_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ select * from renamed

{% if execute %}

{{ log(base_model_sql, info=True) }}
{{ print(base_model_sql) }}
{% do return(base_model_sql) %}

{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion macros/generate_model_import_ctes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@

{%- if execute -%}

{{ log(model_import_ctes, info=True) }}
{{ print(model_import_ctes) }}
{% do return(model_import_ctes) %}

{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion macros/generate_model_yaml.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
{% if execute %}

{% set joined = model_yaml | join ('\n') %}
{{ log(joined, info=True) }}
{{ print(joined) }}
{% do return(joined) %}

{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion macros/generate_source.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
{% if execute %}

{% set joined = sources_yaml | join ('\n') %}
{{ log(joined, info=True) }}
{{ print(joined) }}
{% do return(joined) %}

{% endif %}
Expand Down

0 comments on commit e8b5a02

Please sign in to comment.