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 @@ -80,6 +80,30 @@ func (e *{{.Name}}) Scan(src interface{}) error {
80
80
}
81
81
return nil
82
82
}
83
+
84
+ type Null{{.Name}} struct {
85
+ {{.Name}} {{.Name}}
86
+ Valid bool // Valid is true if String is not NULL
87
+ }
88
+
89
+ // Scan implements the Scanner interface.
90
+ func (ns *Null{{.Name}}) Scan(value interface{}) error {
91
+ if value == nil {
92
+ ns.{{.Name}}, ns.Valid = "", false
93
+ return nil
94
+ }
95
+ ns.Valid = true
96
+ return ns.{{.Name}}.Scan(value)
97
+ }
98
+
99
+ // Value implements the driver Valuer interface.
100
+ func (ns Null{{.Name}}) Value() (driver.Value, error) {
101
+ if !ns.Valid {
102
+ return nil, nil
103
+ }
104
+ return ns.{{.Name}}, nil
105
+ }
106
+
83
107
{{end}}
84
108
85
109
{{range .Structs}}
You can’t perform that action at this time.
0 commit comments