Skip to content

Commit 2618ca0

Browse files
committed
fix: apply go_struct_tag to type overrides
1 parent a353d74 commit 2618ca0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

internal/codegen/golang/go_type.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@ import (
99
)
1010

1111
func addExtraGoStructTags(tags map[string]string, req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) {
12+
columnType := sdk.DataType(col.Type)
13+
notNull := col.NotNull || col.IsArray
14+
15+
// db_type overrides
16+
for _, override := range options.Overrides {
17+
oride := override.ShimOverride
18+
if oride.GoType.StructTags == nil {
19+
continue
20+
}
21+
if oride.DbType == "" || oride.DbType != columnType {
22+
// Different type.
23+
continue
24+
}
25+
if oride.Nullable == notNull {
26+
// Different nullability.
27+
continue
28+
}
29+
if oride.Unsigned != col.Unsigned {
30+
// Different signedness.
31+
continue
32+
}
33+
// Add the extra tags.
34+
for k, v := range oride.GoType.StructTags {
35+
tags[k] = v
36+
}
37+
}
38+
39+
// column overrides are more specific, therefore have higher precedence
1240
for _, override := range options.Overrides {
1341
oride := override.ShimOverride
1442
if oride.GoType.StructTags == nil {

0 commit comments

Comments
 (0)