Skip to content

Commit

Permalink
Update postgresql_type.go - check notNull and emitPointersForNull bef…
Browse files Browse the repository at this point in the history
…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
1 parent ec9d492 commit 2f03435
Showing 1 changed file with 16 additions and 12 deletions.
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

0 comments on commit 2f03435

Please sign in to comment.