@@ -103,55 +103,60 @@ func (t *tmplCtx) codegenQueryRetval(q Query) (string, error) {
103
103
}
104
104
105
105
func Generate (ctx context.Context , req * plugin.CodeGenRequest ) (* plugin.CodeGenResponse , error ) {
106
- enums := buildEnums (req )
107
- structs := buildStructs (req )
108
- queries , err := buildQueries (req , structs )
106
+ options , err := parseOpts (req )
109
107
if err != nil {
110
108
return nil , err
111
109
}
112
110
113
- if req .Settings .Go .OmitUnusedStructs {
111
+ enums := buildEnums (req , options )
112
+ structs := buildStructs (req , options )
113
+ queries , err := buildQueries (req , options , structs )
114
+ if err != nil {
115
+ return nil , err
116
+ }
117
+
118
+ if options .OmitUnusedStructs {
114
119
enums , structs = filterUnusedStructs (enums , structs , queries )
115
120
}
116
121
117
- return generate (req , enums , structs , queries )
122
+ return generate (req , options , enums , structs , queries )
118
123
}
119
124
120
- func generate (req * plugin.CodeGenRequest , enums []Enum , structs []Struct , queries []Query ) (* plugin.CodeGenResponse , error ) {
125
+ func generate (req * plugin.CodeGenRequest , options * opts , enums []Enum , structs []Struct , queries []Query ) (* plugin.CodeGenResponse , error ) {
121
126
i := & importer {
122
127
Settings : req .Settings ,
128
+ Options : options ,
123
129
Queries : queries ,
124
130
Enums : enums ,
125
131
Structs : structs ,
126
132
}
127
133
128
- golang := req .Settings .Go
129
134
tctx := tmplCtx {
130
- EmitInterface : golang .EmitInterface ,
131
- EmitJSONTags : golang .EmitJsonTags ,
132
- JsonTagsIDUppercase : golang .JsonTagsIdUppercase ,
133
- EmitDBTags : golang .EmitDbTags ,
134
- EmitPreparedQueries : golang .EmitPreparedQueries ,
135
- EmitEmptySlices : golang .EmitEmptySlices ,
136
- EmitMethodsWithDBArgument : golang .EmitMethodsWithDbArgument ,
137
- EmitEnumValidMethod : golang .EmitEnumValidMethod ,
138
- EmitAllEnumValues : golang .EmitAllEnumValues ,
135
+ EmitInterface : options .EmitInterface ,
136
+ EmitJSONTags : options .EmitJsonTags ,
137
+ JsonTagsIDUppercase : options .JsonTagsIdUppercase ,
138
+ EmitDBTags : options .EmitDbTags ,
139
+ EmitPreparedQueries : options .EmitPreparedQueries ,
140
+ EmitEmptySlices : options .EmitEmptySlices ,
141
+ EmitMethodsWithDBArgument : options .EmitMethodsWithDbArgument ,
142
+ EmitEnumValidMethod : options .EmitEnumValidMethod ,
143
+ EmitAllEnumValues : options .EmitAllEnumValues ,
139
144
UsesCopyFrom : usesCopyFrom (queries ),
140
145
UsesBatch : usesBatch (queries ),
141
- SQLDriver : parseDriver (golang .SqlPackage ),
146
+ SQLDriver : parseDriver (options .SqlPackage ),
142
147
Q : "`" ,
143
- Package : golang .Package ,
148
+ Package : options .Package ,
144
149
Enums : enums ,
145
150
Structs : structs ,
146
151
SqlcVersion : req .SqlcVersion ,
147
- BuildTags : golang .BuildTags ,
152
+ BuildTags : options .BuildTags ,
148
153
}
149
154
150
- if tctx .UsesCopyFrom && ! tctx .SQLDriver .IsPGX () && golang .SqlDriver != SQLDriverGoSQLDriverMySQL {
155
+ if tctx .UsesCopyFrom && ! tctx .SQLDriver .IsPGX () && options .SqlDriver != SQLDriverGoSQLDriverMySQL {
151
156
return nil , errors .New (":copyfrom is only supported by pgx and github.com/go-sql-driver/mysql" )
152
157
}
153
158
154
- if tctx .UsesCopyFrom && golang .SqlDriver == SQLDriverGoSQLDriverMySQL {
159
+ if tctx .UsesCopyFrom && options .SqlDriver == SQLDriverGoSQLDriverMySQL {
155
160
if err := checkNoTimesForMySQLCopyFrom (queries ); err != nil {
156
161
return nil , err
157
162
}
@@ -208,8 +213,8 @@ func generate(req *plugin.CodeGenRequest, enums []Enum, structs []Struct, querie
208
213
return fmt .Errorf ("source error: %w" , err )
209
214
}
210
215
211
- if templateName == "queryFile" && golang .OutputFilesSuffix != "" {
212
- name += golang .OutputFilesSuffix
216
+ if templateName == "queryFile" && options .OutputFilesSuffix != "" {
217
+ name += options .OutputFilesSuffix
213
218
}
214
219
215
220
if ! strings .HasSuffix (name , ".go" ) {
@@ -220,25 +225,25 @@ func generate(req *plugin.CodeGenRequest, enums []Enum, structs []Struct, querie
220
225
}
221
226
222
227
dbFileName := "db.go"
223
- if golang .OutputDbFileName != "" {
224
- dbFileName = golang .OutputDbFileName
228
+ if options .OutputDbFileName != "" {
229
+ dbFileName = options .OutputDbFileName
225
230
}
226
231
modelsFileName := "models.go"
227
- if golang .OutputModelsFileName != "" {
228
- modelsFileName = golang .OutputModelsFileName
232
+ if options .OutputModelsFileName != "" {
233
+ modelsFileName = options .OutputModelsFileName
229
234
}
230
235
querierFileName := "querier.go"
231
- if golang .OutputQuerierFileName != "" {
232
- querierFileName = golang .OutputQuerierFileName
236
+ if options .OutputQuerierFileName != "" {
237
+ querierFileName = options .OutputQuerierFileName
233
238
}
234
239
copyfromFileName := "copyfrom.go"
235
- if golang .OutputCopyfromFileName != "" {
236
- copyfromFileName = golang .OutputCopyfromFileName
240
+ if options .OutputCopyfromFileName != "" {
241
+ copyfromFileName = options .OutputCopyfromFileName
237
242
}
238
243
239
244
batchFileName := "batch.go"
240
- if golang .OutputBatchFileName != "" {
241
- batchFileName = golang .OutputBatchFileName
245
+ if options .OutputBatchFileName != "" {
246
+ batchFileName = options .OutputBatchFileName
242
247
}
243
248
244
249
if err := execute (dbFileName , "dbFile" ); err != nil {
@@ -247,7 +252,7 @@ func generate(req *plugin.CodeGenRequest, enums []Enum, structs []Struct, querie
247
252
if err := execute (modelsFileName , "modelsFile" ); err != nil {
248
253
return nil , err
249
254
}
250
- if golang .EmitInterface {
255
+ if options .EmitInterface {
251
256
if err := execute (querierFileName , "interfaceFile" ); err != nil {
252
257
return nil , err
253
258
}
0 commit comments