MCPcopy
hub / github.com/sqlc-dev/sqlc / generate

Function generate

internal/codegen/golang/gen.go:166–334  ·  view source on GitHub ↗
(req *plugin.GenerateRequest, options *opts.Options, enums []Enum, structs []Struct, queries []Query)

Source from the content-addressed store, hash-verified

164}
165
166func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum, structs []Struct, queries []Query) (*plugin.GenerateResponse, error) {
167 i := &importer{
168 Options: options,
169 Queries: queries,
170 Enums: enums,
171 Structs: structs,
172 }
173
174 tctx := tmplCtx{
175 EmitInterface: options.EmitInterface,
176 EmitJSONTags: options.EmitJsonTags,
177 JsonTagsIDUppercase: options.JsonTagsIdUppercase,
178 EmitDBTags: options.EmitDbTags,
179 EmitPreparedQueries: options.EmitPreparedQueries,
180 EmitEmptySlices: options.EmitEmptySlices,
181 EmitMethodsWithDBArgument: options.EmitMethodsWithDbArgument,
182 EmitEnumValidMethod: options.EmitEnumValidMethod,
183 EmitAllEnumValues: options.EmitAllEnumValues,
184 UsesCopyFrom: usesCopyFrom(queries),
185 UsesBatch: usesBatch(queries),
186 SQLDriver: parseDriver(options.SqlPackage),
187 Q: "`",
188 Package: options.Package,
189 Enums: enums,
190 Structs: structs,
191 SqlcVersion: req.SqlcVersion,
192 BuildTags: options.BuildTags,
193 OmitSqlcVersion: options.OmitSqlcVersion,
194 WrapErrors: options.WrapErrors,
195 }
196
197 if tctx.UsesCopyFrom && !tctx.SQLDriver.IsPGX() && options.SqlDriver != opts.SQLDriverGoSQLDriverMySQL {
198 return nil, errors.New(":copyfrom is only supported by pgx and github.com/go-sql-driver/mysql")
199 }
200
201 if tctx.UsesCopyFrom && options.SqlDriver == opts.SQLDriverGoSQLDriverMySQL {
202 if err := checkNoTimesForMySQLCopyFrom(queries); err != nil {
203 return nil, err
204 }
205 tctx.SQLDriver = opts.SQLDriverGoSQLDriverMySQL
206 }
207
208 if tctx.UsesBatch && !tctx.SQLDriver.IsPGX() {
209 return nil, errors.New(":batch* commands are only supported by pgx")
210 }
211
212 funcMap := template.FuncMap{
213 "lowerTitle": sdk.LowerTitle,
214 "comment": sdk.DoubleSlashComment,
215 "escape": sdk.EscapeBacktick,
216 "imports": i.Imports,
217 "hasImports": i.HasImports,
218 "hasPrefix": strings.HasPrefix,
219
220 // These methods are Go specific, they do not belong in the codegen package
221 // (as that is language independent)
222 "dbarg": tctx.codegenDbarg,
223 "emitPreparedQueries": tctx.codegenEmitPreparedQueries,

Callers 1

GenerateFunction · 0.85

Calls 8

ImportsMethod · 0.95
usesCopyFromFunction · 0.85
usesBatchFunction · 0.85
parseDriverFunction · 0.85
replaceConflictedArgFunction · 0.85
IsPGXMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected