77
88 "github.com/sqlc-dev/sqlc/internal/codegen/golang/opts"
99 "github.com/sqlc-dev/sqlc/internal/metadata"
10- "github.com/sqlc-dev/sqlc/internal/plugin"
1110)
1211
1312type fileImports struct {
@@ -59,11 +58,10 @@ func mergeImports(imps ...fileImports) [][]ImportSpec {
5958}
6059
6160type importer struct {
62- Settings * plugin.Settings
63- Options * opts.Options
64- Queries []Query
65- Enums []Enum
66- Structs []Struct
61+ Options * opts.Options
62+ Queries []Query
63+ Enums []Enum
64+ Structs []Struct
6765}
6866
6967func (i * importer ) usesType (typ string ) bool {
@@ -157,7 +155,7 @@ var pqtypeTypes = map[string]struct{}{
157155 "pqtype.NullRawMessage" : {},
158156}
159157
160- func buildImports (settings * plugin. Settings , options * opts.Options , queries []Query , uses func (string ) bool ) (map [string ]struct {}, map [ImportSpec ]struct {}) {
158+ func buildImports (options * opts.Options , queries []Query , uses func (string ) bool ) (map [string ]struct {}, map [ImportSpec ]struct {}) {
161159 pkg := make (map [ImportSpec ]struct {})
162160 std := make (map [string ]struct {})
163161
@@ -201,7 +199,8 @@ func buildImports(settings *plugin.Settings, options *opts.Options, queries []Qu
201199 }
202200
203201 overrideTypes := map [string ]string {}
204- for _ , o := range settings .Overrides {
202+ for _ , override := range options .Overrides {
203+ o := override .ShimOverride
205204 if o .GoType .BasicType || o .GoType .TypeName == "" {
206205 continue
207206 }
@@ -226,7 +225,9 @@ func buildImports(settings *plugin.Settings, options *opts.Options, queries []Qu
226225 }
227226
228227 // Custom imports
229- for _ , o := range settings .Overrides {
228+ for _ , override := range options .Overrides {
229+ o := override .ShimOverride
230+
230231 if o .GoType .BasicType || o .GoType .TypeName == "" {
231232 continue
232233 }
@@ -241,7 +242,7 @@ func buildImports(settings *plugin.Settings, options *opts.Options, queries []Qu
241242}
242243
243244func (i * importer ) interfaceImports () fileImports {
244- std , pkg := buildImports (i .Settings , i . Options , i .Queries , func (name string ) bool {
245+ std , pkg := buildImports (i .Options , i .Queries , func (name string ) bool {
245246 for _ , q := range i .Queries {
246247 if q .hasRetType () {
247248 if usesBatch ([]Query {q }) {
@@ -266,7 +267,7 @@ func (i *importer) interfaceImports() fileImports {
266267}
267268
268269func (i * importer ) modelImports () fileImports {
269- std , pkg := buildImports (i .Settings , i . Options , nil , i .usesType )
270+ std , pkg := buildImports (i .Options , nil , i .usesType )
270271
271272 if len (i .Enums ) > 0 {
272273 std ["fmt" ] = struct {}{}
@@ -305,7 +306,7 @@ func (i *importer) queryImports(filename string) fileImports {
305306 }
306307 }
307308
308- std , pkg := buildImports (i .Settings , i . Options , gq , func (name string ) bool {
309+ std , pkg := buildImports (i .Options , gq , func (name string ) bool {
309310 for _ , q := range gq {
310311 if q .hasRetType () {
311312 if q .Ret .EmitStruct () {
@@ -406,7 +407,7 @@ func (i *importer) copyfromImports() fileImports {
406407 copyFromQueries = append (copyFromQueries , q )
407408 }
408409 }
409- std , pkg := buildImports (i .Settings , i . Options , copyFromQueries , func (name string ) bool {
410+ std , pkg := buildImports (i .Options , copyFromQueries , func (name string ) bool {
410411 for _ , q := range copyFromQueries {
411412 if q .hasRetType () {
412413 if strings .HasPrefix (q .Ret .Type (), name ) {
@@ -441,7 +442,7 @@ func (i *importer) batchImports() fileImports {
441442 batchQueries = append (batchQueries , q )
442443 }
443444 }
444- std , pkg := buildImports (i .Settings , i . Options , batchQueries , func (name string ) bool {
445+ std , pkg := buildImports (i .Options , batchQueries , func (name string ) bool {
445446 for _ , q := range batchQueries {
446447 if q .hasRetType () {
447448 if q .Ret .EmitStruct () {
0 commit comments