Skip to content

Commit e8b5a02

Browse files
authored
Merge pull request #86 from JorgenG/use-print-for-outputting-codegen
Use print for outputting codegen
2 parents af12570 + 536246d commit e8b5a02

7 files changed

+22
-5
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ dispatch:
5959

6060
# dbt-codegen v0.8.0
6161

62+
# Unreleased
63+
## Breaking changes
64+
## New features
65+
## Quality of life
66+
- 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
67+
68+
## Under the hood
69+
## Contributors:
70+
- [@JorgenG](https://github.com/JorgenG) (#86)
71+
6272
# dbt-codegen v0.7.0
6373

6474
## 🚨 Breaking change

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ the database to your source definition
6161
* `include_schema` (optional, default=False): Whether you want to add
6262
the schema to your source definition
6363

64+
### Outputting to a file
65+
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:
66+
67+
```
68+
dbt --quiet run-operation generate_model_yaml --args '{"model_name": "stg_jaffle_shop__orders"}' > models/staging/jaffle_shop/stg_jaffle_shop__orders.yml
69+
```
70+
6471
### Usage:
6572
1. Copy the macro into a statement tab in the dbt Cloud IDE, or into an analysis file, and compile your code
6673

dbt_project.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'codegen'
22
version: '0.5.0'
33

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

77
target-path: "target"

macros/generate_base_model.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ select * from renamed
3838

3939
{% if execute %}
4040

41-
{{ log(base_model_sql, info=True) }}
41+
{{ print(base_model_sql) }}
4242
{% do return(base_model_sql) %}
4343

4444
{% endif %}

macros/generate_model_import_ctes.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@
396396

397397
{%- if execute -%}
398398

399-
{{ log(model_import_ctes, info=True) }}
399+
{{ print(model_import_ctes) }}
400400
{% do return(model_import_ctes) %}
401401

402402
{% endif %}

macros/generate_model_yaml.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
{% if execute %}
5050

5151
{% set joined = model_yaml | join ('\n') %}
52-
{{ log(joined, info=True) }}
52+
{{ print(joined) }}
5353
{% do return(joined) %}
5454

5555
{% endif %}

macros/generate_source.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
{% if execute %}
7878

7979
{% set joined = sources_yaml | join ('\n') %}
80-
{{ log(joined, info=True) }}
80+
{{ print(joined) }}
8181
{% do return(joined) %}
8282

8383
{% endif %}

0 commit comments

Comments
 (0)