Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
properly handle nullable and other db_type match parameters
  • Loading branch information
andrewmbenton committed Aug 11, 2025
commit 90dd838d6e89859fc6ddc235927ad5fb993f8f5a
11 changes: 2 additions & 9 deletions internal/codegen/golang/go_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ func addExtraGoStructTags(tags map[string]string, req *plugin.GenerateRequest, o
if oride.GoType.StructTags == nil {
continue
}
if oride.DbType != "" {
columnType := sdk.DataType(col.Type)
if columnType != oride.DbType {
continue
}
if override.MatchesColumn(col) {
for k, v := range oride.GoType.StructTags {
tags[k] = v
}
Expand Down Expand Up @@ -74,16 +70,13 @@ func goType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Colu
}

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

// package overrides have a higher precedence
for _, override := range options.Overrides {
oride := override.ShimOverride
if oride.GoType.TypeName == "" {
continue
}
if oride.DbType != "" && oride.DbType == columnType && oride.Nullable != notNull && oride.Unsigned == col.Unsigned {
if override.MatchesColumn(col) {
return oride.GoType.TypeName
}
}
Expand Down
7 changes: 7 additions & 0 deletions internal/codegen/golang/opts/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"strings"

"github.com/sqlc-dev/sqlc/internal/codegen/sdk"
"github.com/sqlc-dev/sqlc/internal/pattern"
"github.com/sqlc-dev/sqlc/internal/plugin"
)
Expand Down Expand Up @@ -76,6 +77,12 @@ func (o *Override) Matches(n *plugin.Identifier, defaultSchema string) bool {
return true
}

func (o *Override) MatchesColumn(col *plugin.Column) bool {
columnType := sdk.DataType(col.Type)
notNull := col.NotNull || col.IsArray
return o.DBType != "" && o.DBType == columnType && o.Nullable != notNull && o.Unsigned == col.Unsigned
}

func (o *Override) parse(req *plugin.GenerateRequest) (err error) {
// validate deprecated postgres_type field
if o.Deprecated_PostgresType != "" {
Expand Down
Loading