Skip to content

Commit

Permalink
fix: add override tags to result struct (sqlc-dev#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
akutschera committed Oct 8, 2022
1 parent 1a28c29 commit bbd8316
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/codegen/golang/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ func columnsToStruct(req *plugin.CodeGenRequest, name string, columns []goColumn
if req.Settings.Go.EmitJsonTags {
tags["json"] = JSONTagName(tagName, req.Settings)
}
addExtraGoStructTags(tags, req, c.Column)
gs.Fields = append(gs.Fields, Field{
Name: fieldName,
DBName: colName,
Expand Down
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/overrides_result_tag/stdlib/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions internal/endtoend/testdata/overrides_result_tag/stdlib/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CREATE TABLE public.accounts (
id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
state character varying
);

CREATE TABLE public.users_accounts (
ID2 uuid DEFAULT public.uuid_generate_v4() NOT NULL,
name character varying
);

-- name: FindAccount :one
SELECT
a.*,
ua.name
-- other fields
FROM
accounts a
INNER JOIN users_accounts ua ON a.id = ua.id2
WHERE
a.id = @account_id;
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/overrides_result_tag/stdlib/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "2"
sql:
- schema: "query.sql"
queries: "query.sql"
engine: "postgresql"
gen:
go:
package: "querytest"
out: "go"
overrides:
- column: accounts.id
go_struct_tag: sometagtype:"some_value"

0 comments on commit bbd8316

Please sign in to comment.