File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,7 @@ func (i *importer) modelImports() fileImports {
264
264
265
265
if len (i .Enums ) > 0 {
266
266
std ["fmt" ] = struct {}{}
267
+ std ["database/sql/driver" ] = struct {}{}
267
268
}
268
269
269
270
return sortedImports (std , pkg )
Original file line number Diff line number Diff line change @@ -86,6 +86,30 @@ func (e *{{.Name}}) Scan(src interface{}) error {
86
86
}
87
87
return nil
88
88
}
89
+
90
+ type Null{{.Name}} struct {
91
+ {{.Name}} {{.Name}}
92
+ Valid bool // Valid is true if String is not NULL
93
+ }
94
+
95
+ // Scan implements the Scanner interface.
96
+ func (ns *Null{{.Name}}) Scan(value interface{}) error {
97
+ if value == nil {
98
+ ns.{{.Name}}, ns.Valid = "", false
99
+ return nil
100
+ }
101
+ ns.Valid = true
102
+ return ns.{{.Name}}.Scan(value)
103
+ }
104
+
105
+ // Value implements the driver Valuer interface.
106
+ func (ns Null{{.Name}}) Value() (driver.Value, error) {
107
+ if !ns.Valid {
108
+ return nil, nil
109
+ }
110
+ return ns.{{.Name}}, nil
111
+ }
112
+
89
113
{{end}}
90
114
91
115
{{range .Structs}}
You can’t perform that action at this time.
0 commit comments