@@ -111,6 +111,13 @@ func (i *importer) dbImports() fileImports {
111
111
return fileImports {Std : std }
112
112
}
113
113
114
+ var stdlibTypes = map [string ]string {
115
+ "json.RawMessage" : "encoding/json" ,
116
+ "time.Time" : "time" ,
117
+ "net.IP" : "net" ,
118
+ "net.HardwareAddr" : "net" ,
119
+ }
120
+
114
121
func (i * importer ) interfaceImports () fileImports {
115
122
uses := func (name string ) bool {
116
123
for _ , q := range i .Queries {
@@ -139,17 +146,10 @@ func (i *importer) interfaceImports() fileImports {
139
146
std ["database/sql" ] = struct {}{}
140
147
}
141
148
}
142
- if uses ("json.RawMessage" ) {
143
- std ["encoding/json" ] = struct {}{}
144
- }
145
- if uses ("time.Time" ) {
146
- std ["time" ] = struct {}{}
147
- }
148
- if uses ("net.IP" ) {
149
- std ["net" ] = struct {}{}
150
- }
151
- if uses ("net.HardwareAddr" ) {
152
- std ["net" ] = struct {}{}
149
+ for typeName , pkg := range stdlibTypes {
150
+ if uses (typeName ) {
151
+ std [pkg ] = struct {}{}
152
+ }
153
153
}
154
154
155
155
pkg := make (map [ImportSpec ]struct {})
@@ -202,17 +202,10 @@ func (i *importer) modelImports() fileImports {
202
202
if i .usesType ("sql.Null" ) {
203
203
std ["database/sql" ] = struct {}{}
204
204
}
205
- if i .usesType ("json.RawMessage" ) {
206
- std ["encoding/json" ] = struct {}{}
207
- }
208
- if i .usesType ("time.Time" ) {
209
- std ["time" ] = struct {}{}
210
- }
211
- if i .usesType ("net.IP" ) {
212
- std ["net" ] = struct {}{}
213
- }
214
- if i .usesType ("net.HardwareAddr" ) {
215
- std ["net" ] = struct {}{}
205
+ for typeName , pkg := range stdlibTypes {
206
+ if i .usesType (typeName ) {
207
+ std [pkg ] = struct {}{}
208
+ }
216
209
}
217
210
if len (i .Enums ) > 0 {
218
211
std ["fmt" ] = struct {}{}
@@ -347,14 +340,10 @@ func (i *importer) queryImports(filename string) fileImports {
347
340
std ["database/sql" ] = struct {}{}
348
341
}
349
342
}
350
- if uses ("json.RawMessage" ) {
351
- std ["encoding/json" ] = struct {}{}
352
- }
353
- if uses ("time.Time" ) {
354
- std ["time" ] = struct {}{}
355
- }
356
- if uses ("net.IP" ) {
357
- std ["net" ] = struct {}{}
343
+ for typeName , pkg := range stdlibTypes {
344
+ if uses (typeName ) {
345
+ std [pkg ] = struct {}{}
346
+ }
358
347
}
359
348
360
349
pkg := make (map [ImportSpec ]struct {})
0 commit comments