Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use print for outputting codegen #86

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
- [@handle](https://github.com/handle) (#XXX)
--->

# 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 @@ -44,6 +44,13 @@ want to subselect from all available tables within a given schema.
* `exclude` (optional, default=''): A string you want to exclude from the selection criteria
* `name` (optional, default=schema_name): The name of your source

### 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 @@ -33,7 +33,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 @@ -167,7 +167,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 @@ -39,7 +39,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 @@ -74,7 +74,7 @@
{% if execute %}

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

{% endif %}
Expand Down