From 2f034358596220a53581aebc3d01f9275bbeab86 Mon Sep 17 00:00:00 2001 From: Anurag Mishra <86455065+theAnuragMishra@users.noreply.github.com> Date: Thu, 13 Feb 2025 00:22:53 +0530 Subject: [PATCH] Update postgresql_type.go - check notNull and emitPointersForNull before 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. --- internal/codegen/golang/postgresql_type.go | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/internal/codegen/golang/postgresql_type.go b/internal/codegen/golang/postgresql_type.go index 4518e1aba6..578fd04b8e 100644 --- a/internal/codegen/golang/postgresql_type.go +++ b/internal/codegen/golang/postgresql_type.go @@ -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": @@ -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": @@ -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":