Skip to content

Commit 0bd4f68

Browse files
fix(postgresql_type.go): fix logic sequence that cause emit_pointers_for_null_types not working
1 parent 53b12f9 commit 0bd4f68

File tree

1 file changed

+61
-61
lines changed

1 file changed

+61
-61
lines changed

internal/codegen/golang/postgresql_type.go

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -42,102 +42,105 @@ 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
}
5148
if driver == opts.SQLDriverPGXV5 {
5249
return "pgtype.Int4"
5350
}
51+
if notNull {
52+
return "int32"
53+
}
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
}
6360
if driver == opts.SQLDriverPGXV5 {
6461
return "pgtype.Int8"
6562
}
63+
if notNull {
64+
return "int64"
65+
}
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
}
7572
if driver == opts.SQLDriverPGXV5 {
7673
return "pgtype.Int2"
7774
}
75+
if notNull {
76+
return "int16"
77+
}
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
}
8784
if driver == opts.SQLDriverPGXV5 {
8885
return "pgtype.Int4"
8986
}
87+
if notNull {
88+
return "int32"
89+
}
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
}
9996
if driver == opts.SQLDriverPGXV5 {
10097
return "pgtype.Int8"
10198
}
99+
if notNull {
100+
return "int64"
101+
}
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
}
111108
if driver == opts.SQLDriverPGXV5 {
112109
return "pgtype.Int2"
113110
}
111+
if notNull {
112+
return "int16"
113+
}
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
}
123120
if driver == opts.SQLDriverPGXV5 {
124121
return "pgtype.Float8"
125122
}
123+
if notNull {
124+
return "float64"
125+
}
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
}
135132
if driver == opts.SQLDriverPGXV5 {
136133
return "pgtype.Float4"
137134
}
135+
if notNull {
136+
return "float32"
137+
}
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 emitPointersForNull {
142+
return "*string"
143+
}
141144
if driver.IsPGX() {
142145
return "pgtype.Numeric"
143146
}
@@ -148,21 +151,18 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
148151
if notNull {
149152
return "string"
150153
}
151-
if emitPointersForNull {
152-
return "*string"
153-
}
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
}
163160
if driver == opts.SQLDriverPGXV5 {
164161
return "pgtype.Bool"
165162
}
163+
if notNull {
164+
return "bool"
165+
}
166166
return "sql.NullBool"
167167

168168
case "json", "pg_catalog.json":
@@ -200,85 +200,85 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
200200
case "bytea", "blob", "pg_catalog.bytea":
201201
return "[]byte"
202202

203-
case "date":
203+
case "date":
204+
if emitPointersForNull {
205+
return "*time.Time"
206+
}
204207
if driver == opts.SQLDriverPGXV5 {
205208
return "pgtype.Date"
206209
}
207210
if notNull {
208211
return "time.Time"
209212
}
210-
if emitPointersForNull {
211-
return "*time.Time"
212-
}
213213
return "sql.NullTime"
214214

215215
case "pg_catalog.time":
216+
if emitPointersForNull {
217+
return "*time.Time"
218+
}
216219
if driver == opts.SQLDriverPGXV5 {
217220
return "pgtype.Time"
218221
}
219222
if notNull {
220223
return "time.Time"
221224
}
222-
if emitPointersForNull {
223-
return "*time.Time"
224-
}
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 emitPointersForNull {
238+
return "*time.Time"
239+
}
237240
if driver == opts.SQLDriverPGXV5 {
238241
return "pgtype.Timestamp"
239242
}
240243
if notNull {
241244
return "time.Time"
242245
}
243-
if emitPointersForNull {
244-
return "*time.Time"
245-
}
246246
return "sql.NullTime"
247247

248248
case "pg_catalog.timestamptz", "timestamptz":
249+
if emitPointersForNull {
250+
return "*time.Time"
251+
}
249252
if driver == opts.SQLDriverPGXV5 {
250253
return "pgtype.Timestamptz"
251254
}
252255
if notNull {
253256
return "time.Time"
254257
}
255-
if emitPointersForNull {
256-
return "*time.Time"
257-
}
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
}
267264
if driver == opts.SQLDriverPGXV5 {
268265
return "pgtype.Text"
269266
}
267+
if notNull {
268+
return "string"
269+
}
270270
return "sql.NullString"
271271

272272
case "uuid":
273+
if emitPointersForNull {
274+
return "*uuid.UUID"
275+
}
273276
if driver == opts.SQLDriverPGXV5 {
274277
return "pgtype.UUID"
275278
}
276279
if notNull {
277280
return "uuid.UUID"
278281
}
279-
if emitPointersForNull {
280-
return "*uuid.UUID"
281-
}
282282
return "uuid.NullUUID"
283283

284284
case "inet":
@@ -324,6 +324,12 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
324324
}
325325

326326
case "ltree", "lquery", "ltxtquery":
327+
if emitPointersForNull {
328+
return "*string"
329+
}
330+
if driver == opts.SQLDriverPGXV5 {
331+
return "pgtype.Text"
332+
}
327333
// This module implements a data type ltree for representing labels
328334
// of data stored in a hierarchical tree-like structure. Extensive
329335
// facilities for searching through label trees are provided.
@@ -332,24 +338,18 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
332338
if notNull {
333339
return "string"
334340
}
335-
if emitPointersForNull {
336-
return "*string"
337-
}
338-
if driver == opts.SQLDriverPGXV5 {
339-
return "pgtype.Text"
340-
}
341341
return "sql.NullString"
342342

343343
case "interval", "pg_catalog.interval":
344+
if emitPointersForNull {
345+
return "*int64"
346+
}
344347
if driver == opts.SQLDriverPGXV5 {
345348
return "pgtype.Interval"
346349
}
347350
if notNull {
348351
return "int64"
349352
}
350-
if emitPointersForNull {
351-
return "*int64"
352-
}
353353
return "sql.NullInt64"
354354

355355
case "daterange":

0 commit comments

Comments
 (0)