■ はじめに
https://dk521123.hatenablog.com/entry/2023/05/30/151003
でも少し触れたが、DBT の ドキュメント化について 徐々にまとめていく
目次
【1】公式ドキュメント 【2】dbt docs コマンド 0)dbt docs -h 1)dbt docs generate 2)dbt docs serve 【3】サンプル 1)別ファイルに分ける
【1】公式ドキュメント
https://docs.getdbt.com/docs/collaborate/documentation
https://docs.getdbt.com/reference/commands/cmd-docs
【2】dbt docs コマンド
* DBT の ドキュメント関連のコマンド
0)dbt docs -h
dbt docs -h dbt docs generate -h dbt docs serve -h
1)dbt docs generate
* ドキュメントをJSON形式で生成する
https://dev.classmethod.jp/articles/dbt-documentation/
dbt docs generate 08:59:38 Running with dbt=1.5.0 ・・・略・・・ 08:59:39 Catalog written to C:\xxxx\hello_world\users\target\catalog.json
2)dbt docs serve
* ドキュメントを生成する
例
# Port 28080 を指定 dbt docs serve --port 8001
構文
dbt docs serve \ [--profiles-dir PROFILES_DIR] \ [--profile PROFILE] \ [--target TARGET] \ [--port PORT] \ [--no-browser]
【3】サンプル
1)別ファイルに分ける
models/customers.sql
{{ config( alias='hello', schema='demo_schema', database='sample_db', materialized='table' ) }} select 1 as id, 'Mike' as name, '{{ var("remark", "hello_world") }}' as remark, now() as insert_at
models/schema.yml
version: 2 models: - name: customers # description: This table contains customer data description: '{{ doc("table_customers") }}' columns: - name: id description: This is a unique identifier for the customers - name: name quote: true description: The customer name - name: remark quote: true description: Just remark - name: insert_at quote: true description: Registration date
models/customers.md
{% docs table_customers %} The table of customers are recorded: - / - /id - /name - /remark - /insert_at {% enddocs %}
ドキュメント化
dbt docs generate # Port 28080 を指定 dbt docs serve --port 8001
関連記事
dbt ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2023/06/30/000000
dbt ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2023/05/30/151003
dbt ~ 基本編 / Model ~
https://dk521123.hatenablog.com/entry/2023/11/25/231128
dbt ~ 基本編 / Seed ~
https://dk521123.hatenablog.com/entry/2023/11/20/230946
dbt ~ 基本編 / Source ~
https://dk521123.hatenablog.com/entry/2023/12/08/111012