@@ -13,20 +13,27 @@ func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.C
13
13
columnType := sdk .DataType (col .Type )
14
14
notNull := col .NotNull || col .IsArray
15
15
unsigned := col .Unsigned
16
+ emitPointersForNull := options .EmitPointersForNullTypes
16
17
17
18
switch columnType {
18
19
19
20
case "varchar" , "text" , "char" , "tinytext" , "mediumtext" , "longtext" :
20
21
if notNull {
21
22
return "string"
22
23
}
24
+ if emitPointersForNull {
25
+ return "*string"
26
+ }
23
27
return "sql.NullString"
24
28
25
29
case "tinyint" :
26
30
if col .Length == 1 {
27
31
if notNull {
28
32
return "bool"
29
33
}
34
+ if emitPointersForNull {
35
+ return "*bool"
36
+ }
30
37
return "sql.NullBool"
31
38
} else {
32
39
if notNull {
@@ -35,6 +42,12 @@ func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.C
35
42
}
36
43
return "int8"
37
44
}
45
+ if emitPointersForNull {
46
+ if unsigned {
47
+ return "*uint8"
48
+ }
49
+ return "*int8"
50
+ }
38
51
// The database/sql package does not have a sql.NullInt8 type, so we
39
52
// use the smallest type they have which is NullInt16
40
53
return "sql.NullInt16"
@@ -44,6 +57,9 @@ func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.C
44
57
if notNull {
45
58
return "int16"
46
59
}
60
+ if emitPointersForNull {
61
+ return "*int16"
62
+ }
47
63
return "sql.NullInt16"
48
64
49
65
case "smallint" :
@@ -53,6 +69,12 @@ func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.C
53
69
}
54
70
return "int16"
55
71
}
72
+ if emitPointersForNull {
73
+ if unsigned {
74
+ return "*uint16"
75
+ }
76
+ return "*int16"
77
+ }
56
78
return "sql.NullInt16"
57
79
58
80
case "int" , "integer" , "mediumint" :
@@ -62,6 +84,12 @@ func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.C
62
84
}
63
85
return "int32"
64
86
}
87
+ if emitPointersForNull {
88
+ if unsigned {
89
+ return "*uint32"
90
+ }
91
+ return "*int32"
92
+ }
65
93
return "sql.NullInt32"
66
94
67
95
case "bigint" :
@@ -71,6 +99,12 @@ func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.C
71
99
}
72
100
return "int64"
73
101
}
102
+ if emitPointersForNull {
103
+ if unsigned {
104
+ return "*uint64"
105
+ }
106
+ return "*int64"
107
+ }
74
108
return "sql.NullInt64"
75
109
76
110
case "blob" , "binary" , "varbinary" , "tinyblob" , "mediumblob" , "longblob" :
@@ -83,12 +117,18 @@ func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.C
83
117
if notNull {
84
118
return "float64"
85
119
}
120
+ if emitPointersForNull {
121
+ return "*float64"
122
+ }
86
123
return "sql.NullFloat64"
87
124
88
125
case "decimal" , "dec" , "fixed" :
89
126
if notNull {
90
127
return "string"
91
128
}
129
+ if emitPointersForNull {
130
+ return "*string"
131
+ }
92
132
return "sql.NullString"
93
133
94
134
case "enum" :
@@ -99,12 +139,18 @@ func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.C
99
139
if notNull {
100
140
return "time.Time"
101
141
}
142
+ if emitPointersForNull {
143
+ return "*time.Time"
144
+ }
102
145
return "sql.NullTime"
103
146
104
147
case "boolean" , "bool" :
105
148
if notNull {
106
149
return "bool"
107
150
}
151
+ if emitPointersForNull {
152
+ return "*bool"
153
+ }
108
154
return "sql.NullBool"
109
155
110
156
case "json" :
0 commit comments