Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update postgresql_type.go - check notNull and emitPointersForNull bef…
…ore SQLDriver

this fixes the issue where despite having emit_pointers_for_null_types set to true, the generate models don't use pointers for timestamp field.
  • Loading branch information
theAnuragMishra authored Feb 12, 2025
commit 2f034358596220a53581aebc3d01f9275bbeab86
28 changes: 16 additions & 12 deletions internal/codegen/golang/postgresql_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,16 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
return "sql.NullTime"

case "pg_catalog.time":
if driver == opts.SQLDriverPGXV5 {
return "pgtype.Time"
}
if notNull {
return "time.Time"
}
if emitPointersForNull {
return "*time.Time"
}
if driver == opts.SQLDriverPGXV5 {
return "pgtype.Time"
}

return "sql.NullTime"

case "pg_catalog.timetz":
Expand All @@ -234,27 +235,29 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
return "sql.NullTime"

case "pg_catalog.timestamp", "timestamp":
if driver == opts.SQLDriverPGXV5 {
return "pgtype.Timestamp"
}
if notNull {
return "time.Time"
}
if emitPointersForNull {
return "*time.Time"
}
if driver == opts.SQLDriverPGXV5 {
return "pgtype.Timestamp"
}

return "sql.NullTime"

case "pg_catalog.timestamptz", "timestamptz":
if driver == opts.SQLDriverPGXV5 {
return "pgtype.Timestamptz"
}
if notNull {
return "time.Time"
}
if emitPointersForNull {
return "*time.Time"
}
if driver == opts.SQLDriverPGXV5 {
return "pgtype.Timestamptz"
}

return "sql.NullTime"

case "text", "pg_catalog.varchar", "pg_catalog.bpchar", "string", "citext", "name":
Expand All @@ -270,15 +273,16 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
return "sql.NullString"

case "uuid":
if driver == opts.SQLDriverPGXV5 {
return "pgtype.UUID"
}

if notNull {
return "uuid.UUID"
}
if emitPointersForNull {
return "*uuid.UUID"
}
if driver == opts.SQLDriverPGXV5 {
return "pgtype.UUID"
}
return "uuid.NullUUID"

case "inet":
Expand Down
Loading