@@ -42,104 +42,104 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
4242
4343 switch columnType {
4444 case "serial" , "serial4" , "pg_catalog.serial4" :
45- if notNull {
46- return "int32"
47- }
4845 if emitPointersForNull {
4946 return "*int32"
5047 }
48+ if notNull {
49+ return "int32"
50+ }
5151 if driver == opts .SQLDriverPGXV5 {
5252 return "pgtype.Int4"
5353 }
5454 return "sql.NullInt32"
5555
5656 case "bigserial" , "serial8" , "pg_catalog.serial8" :
57- if notNull {
58- return "int64"
59- }
6057 if emitPointersForNull {
6158 return "*int64"
6259 }
60+ if notNull {
61+ return "int64"
62+ }
6363 if driver == opts .SQLDriverPGXV5 {
6464 return "pgtype.Int8"
6565 }
6666 return "sql.NullInt64"
6767
6868 case "smallserial" , "serial2" , "pg_catalog.serial2" :
69- if notNull {
70- return "int16"
71- }
7269 if emitPointersForNull {
7370 return "*int16"
7471 }
72+ if notNull {
73+ return "int16"
74+ }
7575 if driver == opts .SQLDriverPGXV5 {
7676 return "pgtype.Int2"
7777 }
7878 return "sql.NullInt16"
7979
8080 case "integer" , "int" , "int4" , "pg_catalog.int4" :
81- if notNull {
82- return "int32"
83- }
8481 if emitPointersForNull {
8582 return "*int32"
8683 }
84+ if notNull {
85+ return "int32"
86+ }
8787 if driver == opts .SQLDriverPGXV5 {
8888 return "pgtype.Int4"
8989 }
9090 return "sql.NullInt32"
9191
9292 case "bigint" , "int8" , "pg_catalog.int8" :
93- if notNull {
94- return "int64"
95- }
9693 if emitPointersForNull {
9794 return "*int64"
9895 }
96+ if notNull {
97+ return "int64"
98+ }
9999 if driver == opts .SQLDriverPGXV5 {
100100 return "pgtype.Int8"
101101 }
102102 return "sql.NullInt64"
103103
104104 case "smallint" , "int2" , "pg_catalog.int2" :
105- if notNull {
106- return "int16"
107- }
108105 if emitPointersForNull {
109106 return "*int16"
110107 }
108+ if notNull {
109+ return "int16"
110+ }
111111 if driver == opts .SQLDriverPGXV5 {
112112 return "pgtype.Int2"
113113 }
114114 return "sql.NullInt16"
115115
116116 case "float" , "double precision" , "float8" , "pg_catalog.float8" :
117- if notNull {
118- return "float64"
119- }
120117 if emitPointersForNull {
121118 return "*float64"
122119 }
120+ if notNull {
121+ return "float64"
122+ }
123123 if driver == opts .SQLDriverPGXV5 {
124124 return "pgtype.Float8"
125125 }
126126 return "sql.NullFloat64"
127127
128128 case "real" , "float4" , "pg_catalog.float4" :
129- if notNull {
130- return "float32"
131- }
132129 if emitPointersForNull {
133130 return "*float32"
134131 }
132+ if notNull {
133+ return "float32"
134+ }
135135 if driver == opts .SQLDriverPGXV5 {
136136 return "pgtype.Float4"
137137 }
138138 return "sql.NullFloat64" // TODO: Change to sql.NullFloat32 after updating the go.mod file
139139
140140 case "numeric" , "pg_catalog.numeric" , "money" :
141- if driver . IsPGX () {
142- return "pgtype.Numeric "
141+ if emitPointersForNull {
142+ return "*string "
143143 }
144144 // Since the Go standard library does not have a decimal type, lib/pq
145145 // returns numerics as strings.
@@ -148,18 +148,18 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
148148 if notNull {
149149 return "string"
150150 }
151- if emitPointersForNull {
152- return "*string "
151+ if driver . IsPGX () {
152+ return "pgtype.Numeric "
153153 }
154154 return "sql.NullString"
155155
156156 case "boolean" , "bool" , "pg_catalog.bool" :
157- if notNull {
158- return "bool"
159- }
160157 if emitPointersForNull {
161158 return "*bool"
162159 }
160+ if notNull {
161+ return "bool"
162+ }
163163 if driver == opts .SQLDriverPGXV5 {
164164 return "pgtype.Bool"
165165 }
@@ -200,84 +200,84 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
200200 case "bytea" , "blob" , "pg_catalog.bytea" :
201201 return "[]byte"
202202
203- case "date" :
204- if driver == opts . SQLDriverPGXV5 {
205- return "pgtype.Date "
203+ case "date" :
204+ if emitPointersForNull {
205+ return "*time.Time "
206206 }
207207 if notNull {
208208 return "time.Time"
209209 }
210- if emitPointersForNull {
211- return "*time.Time "
210+ if driver == opts . SQLDriverPGXV5 {
211+ return "pgtype.Date "
212212 }
213213 return "sql.NullTime"
214214
215215 case "pg_catalog.time" :
216- if driver == opts . SQLDriverPGXV5 {
217- return "pgtype .Time"
216+ if emitPointersForNull {
217+ return "*time .Time"
218218 }
219219 if notNull {
220220 return "time.Time"
221221 }
222- if emitPointersForNull {
223- return "*time .Time"
222+ if driver == opts . SQLDriverPGXV5 {
223+ return "pgtype .Time"
224224 }
225225 return "sql.NullTime"
226226
227227 case "pg_catalog.timetz" :
228- if notNull {
229- return "time.Time"
230- }
231228 if emitPointersForNull {
232229 return "*time.Time"
233230 }
231+ if notNull {
232+ return "time.Time"
233+ }
234234 return "sql.NullTime"
235235
236236 case "pg_catalog.timestamp" , "timestamp" :
237- if driver == opts . SQLDriverPGXV5 {
238- return "pgtype.Timestamp "
237+ if emitPointersForNull {
238+ return "*time.Time "
239239 }
240240 if notNull {
241241 return "time.Time"
242242 }
243- if emitPointersForNull {
244- return "*time.Time "
243+ if driver == opts . SQLDriverPGXV5 {
244+ return "pgtype.Timestamp "
245245 }
246246 return "sql.NullTime"
247247
248248 case "pg_catalog.timestamptz" , "timestamptz" :
249- if driver == opts . SQLDriverPGXV5 {
250- return "pgtype.Timestamptz "
249+ if emitPointersForNull {
250+ return "*time.Time "
251251 }
252252 if notNull {
253253 return "time.Time"
254254 }
255- if emitPointersForNull {
256- return "*time.Time "
255+ if driver == opts . SQLDriverPGXV5 {
256+ return "pgtype.Timestamptz "
257257 }
258258 return "sql.NullTime"
259259
260260 case "text" , "pg_catalog.varchar" , "pg_catalog.bpchar" , "string" , "citext" , "name" :
261- if notNull {
262- return "string"
263- }
264261 if emitPointersForNull {
265262 return "*string"
266263 }
264+ if notNull {
265+ return "string"
266+ }
267267 if driver == opts .SQLDriverPGXV5 {
268268 return "pgtype.Text"
269269 }
270270 return "sql.NullString"
271271
272272 case "uuid" :
273- if driver == opts . SQLDriverPGXV5 {
274- return "pgtype .UUID"
273+ if emitPointersForNull {
274+ return "*uuid .UUID"
275275 }
276276 if notNull {
277277 return "uuid.UUID"
278278 }
279- if emitPointersForNull {
280- return "*uuid .UUID"
279+ if driver == opts . SQLDriverPGXV5 {
280+ return "pgtype .UUID"
281281 }
282282 return "uuid.NullUUID"
283283
@@ -324,6 +324,9 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
324324 }
325325
326326 case "ltree" , "lquery" , "ltxtquery" :
327+ if emitPointersForNull {
328+ return "*string"
329+ }
327330 // This module implements a data type ltree for representing labels
328331 // of data stored in a hierarchical tree-like structure. Extensive
329332 // facilities for searching through label trees are provided.
@@ -332,23 +335,20 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
332335 if notNull {
333336 return "string"
334337 }
335- if emitPointersForNull {
336- return "*string"
337- }
338338 if driver == opts .SQLDriverPGXV5 {
339339 return "pgtype.Text"
340340 }
341341 return "sql.NullString"
342342
343343 case "interval" , "pg_catalog.interval" :
344- if driver == opts . SQLDriverPGXV5 {
345- return "pgtype.Interval "
344+ if emitPointersForNull {
345+ return "*int64 "
346346 }
347347 if notNull {
348348 return "int64"
349349 }
350- if emitPointersForNull {
351- return "*int64 "
350+ if driver == opts . SQLDriverPGXV5 {
351+ return "pgtype.Interval "
352352 }
353353 return "sql.NullInt64"
354354
0 commit comments