Skip to content
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
36 changes: 26 additions & 10 deletions internal/codegen/golang/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,35 @@ import (
"github.com/sqlc-dev/sqlc/internal/plugin"
)

func (g *Generator) goType(col *plugin.Column) string {
// Existing logic...
// Add logic to check if column is nullable and is an array type
if col.NotNull == false && isArrayType(col.Type) {
return "*[]" + baseType(col.Type)
// GoType returns the Go type for a database column, handling nullable array types correctly.
func (g *Generator) GoType(col *plugin.Column, settings Settings) string {
typ := g.dbType(col, settings)

if col.IsArray {
if !col.NotNull {
// Nullable array columns map to *[]Type for standard lib/pq scanning
return "*[]" + typ
}
return "[]" + typ
}

if !col.NotNull {
if settings.GoTypePointer {
return "*" + typ
}
return g.nullableType(typ, settings)
}
return g.defaultGoType(col)

return typ
}

func isArrayType(t string) bool {
return t == "uuid[]" // Simplified for demonstration
func (g *Generator) dbType(col *plugin.Column, settings Settings) string {
if col.Type.Name == "uuid" {
return "uuid.UUID"
}
return col.Type.Name
}

func baseType(t string) string {
return "uuid.UUID"
func (g *Generator) nullableType(typ string, settings Settings) string {
return "*" + typ
}