dbt-codegen is a powerful dbt extension package that helps us automatically generate various dbt code, significantly improving development efficiency. Simply put, it acts as an intelligent assistant that can help us generate:
Let's start with the basics of installation:
packages.yml
file in your dbt project (create one if it doesn't exist)packages:
- package: dbt-labs/codegen
version: 0.9.0 # Use the latest version
dbt deps
to install the packageThis is one of the most commonly used features that can automatically scan the database to generate source definitions.
Basic usage:
{{ codegen.generate_source('raw_schema_name') }}
Advanced usage: