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

General examples of calling a macro in a hook #5972

Merged
merged 6 commits into from
Sep 5, 2024
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
35 changes: 35 additions & 0 deletions website/docs/docs/build/hooks-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,41 @@ You can use hooks to provide database-specific functionality not available out-o

You can also use a [macro](/docs/build/jinja-macros#macros) to bundle up hook logic. Check out some of the examples in the reference sections for [on-run-start and on-run-end hooks](/reference/project-configs/on-run-start-on-run-end) and [pre- and post-hooks](/reference/resource-configs/pre-hook-post-hook).

<File name='models/<model_name>.sql'>

```sql
{{ config(
pre_hook=[
"{{ some_macro() }}"
]
) }}
```

</File>

<File name='models/properties.yml'>

```yaml
models:
- name: <model_name>
config:
pre_hook:
- "{{ some_macro() }}"
```

</File>

<File name='dbt_project.yml'>

```yaml
models:
<project_name>:
+pre-hook:
- "{{ some_macro() }}"
```

</File>

## About operations

Operations are [macros](/docs/build/jinja-macros#macros) that you can run using the [`run-operation`](/reference/commands/run-operation) command. As such, operations aren't actually a separate resource in your dbt project — they are just a convenient way to invoke a macro without needing to run a model.
Expand Down
36 changes: 36 additions & 0 deletions website/docs/reference/resource-configs/pre-hook-post-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ select ...
```


</File>

<File name='models/properties.yml'>

```yml
models:
- name: [<model_name>]
config:
[pre_hook](/reference/resource-configs/pre-hook-post-hook): <sql-statement> | [<sql-statement>]
[post_hook](/reference/resource-configs/pre-hook-post-hook): <sql-statement> | [<sql-statement>]
```

</File>

</TabItem>
Expand All @@ -66,6 +78,18 @@ seeds:

</File>

<File name='seeds/properties.yml'>

```yml
seeds:
- name: [<seed_name>]
config:
[pre_hook](/reference/resource-configs/pre-hook-post-hook): <sql-statement> | [<sql-statement>]
[post_hook](/reference/resource-configs/pre-hook-post-hook): <sql-statement> | [<sql-statement>]
```

</File>

</TabItem>

<TabItem value="snapshots">
Expand Down Expand Up @@ -102,6 +126,18 @@ select ...

</File>

<File name='snapshots/properties.yml'>

```yml
snapshots:
- name: [<snapshot_name>]
config:
[pre_hook](/reference/resource-configs/pre-hook-post-hook): <sql-statement> | [<sql-statement>]
[post_hook](/reference/resource-configs/pre-hook-post-hook): <sql-statement> | [<sql-statement>]
```

</File>

</TabItem>

</Tabs>
Expand Down
Loading