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

Apply go_struct_tag to type overrides #3564

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions internal/codegen/golang/go_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ import (
)

func addExtraGoStructTags(tags map[string]string, req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) {
columnType := sdk.DataType(col.Type)
notNull := col.NotNull || col.IsArray

// db_type overrides
for _, override := range options.Overrides {
oride := override.ShimOverride
if oride.GoType.StructTags == nil {
continue
}
if oride.DbType == "" || oride.DbType != columnType {
// Different type.
continue
}
if oride.Nullable == notNull {
// Different nullability.
continue
}
if oride.Unsigned != col.Unsigned {
// Different signedness.
continue
}
// Add the extra tags.
for k, v := range oride.GoType.StructTags {
tags[k] = v
}
}

// column overrides are more specific, therefore have higher precedence
for _, override := range options.Overrides {
oride := override.ShimOverride
if oride.GoType.StructTags == nil {
Expand Down