Skip to content

Commit

Permalink
docs: add more documentation for emit_embed_alias
Browse files Browse the repository at this point in the history
  • Loading branch information
sapk committed Dec 28, 2023
1 parent c6c7e0c commit 32079a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion docs/howto/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,24 @@ type ScoreAndTestsRow struct {
Student Student
TestScore TestScore
}
```
```

sqlc can generate structs with fields based on the alias inside the macro `sqlc.embed()` by adding the `emit_embed_alias` key to the configuration file as it shows on [configuration reference](../reference/config.md).

```sql
-- name: ListUserLink :many
SELECT
sqlc.embed(owner),
sqlc.embed(consumer)
FROM
user_links
INNER JOIN users AS owner ON owner.id = user_links.owner_id
INNER JOIN users AS consumer ON consumer.id = user_links.consumer_id;
```

```
type ListUserLinkRow struct {
Owner User
Consumer User
}
```
4 changes: 2 additions & 2 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ The `gen` mapping supports the following keys:
- If true, emit a function per enum type
that returns all valid enum values.
- `emit_embed_alias`:
- If true, use alias name inside `sqlc.embed()` function instead of table name for field name. Defaults to `false`.
- If true, use alias name inside `sqlc.embed()` macro instead of table name for field name. Defaults to `false`.
- `build_tags`:
- If set, add a `//go:build <build_tags>` directive at the beginning of each generated Go file.
- `json_tags_id_uppercase`:
Expand Down Expand Up @@ -467,7 +467,7 @@ Each mapping in the `packages` collection has the following keys:
- If true, emit a function per enum type
that returns all valid enum values.
- `emit_embed_alias`:
- If true, use alias name inside `sqlc.embed()` function instead of table name for field name. Defaults to `false`.
- If true, use alias name inside `sqlc.embed()` macro instead of table name for field name. Defaults to `false`.
- `build_tags`:
- If set, add a `//go:build <build_tags>` directive at the beginning of each generated Go file.
- `json_tags_case_style`:
Expand Down

0 comments on commit 32079a0

Please sign in to comment.