Skip to content

Commit 4901dde

Browse files
EliSauderCopilot
andcommitted
fix(golang): resolve one domain at a time on the core path
resolveDomains replaced a whole chain of domains with the last base, so goInnerType never checked an override on a domain in the middle of the chain: with validated_id AS id AS text, a db_type override on id generated string. Replace one domain per step, as the legacy path does, and let goInnerType check overrides between steps. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0d0e784 commit 4901dde

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎internal/codegen/golang/domain_type.go‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ func flatType(t *plugin.TypeExpr) (string, int32) {
5454
// nullability t says each position has.
5555
func resolveDomains(req *plugin.GenerateRequest, t *plugin.TypeExpr) (*plugin.TypeExpr, bool) {
5656
if d := findDomain(req, "", t.GetName()); !baseless(req, d) {
57+
// One domain at a time, so an override on a domain under it applies.
5758
base := proto.Clone(d.Base).(*plugin.TypeExpr)
5859
base.Nullable = t.Nullable
59-
if resolved, ok := resolveDomains(req, base); ok {
60-
return resolved, true
61-
}
6260
return base, true
6361
}
6462
var out *plugin.TypeExpr

‎internal/endtoend/testdata/domain_types/postgresql_core/go/models.go‎

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
CREATE DOMAIN tags AS text[];
22
CREATE DOMAIN title AS varchar(100) NOT NULL;
3+
-- An override on the domain a domain stands on applies to it.
4+
CREATE DOMAIN id AS text;
5+
CREATE DOMAIN validated_id AS id;
36

47
CREATE TABLE shelves (
58
id serial PRIMARY KEY,
69
titles title[] NOT NULL,
710
tags tags NOT NULL,
811
tag_sets tags[] NOT NULL
912
);
13+
14+
CREATE TABLE things (
15+
ref validated_id NOT NULL,
16+
refs validated_id[] NOT NULL
17+
);

‎internal/endtoend/testdata/domain_types/postgresql_core/sqlc.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ sql:
88
package: "querytest"
99
out: "go"
1010
sql_package: "pgx/v5"
11+
overrides:
12+
- db_type: "id"
13+
go_type: "github.com/google/uuid.UUID"

0 commit comments

Comments
 (0)