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

Function buildQueries

internal/codegen/golang/result.go:184–348  ·  view source on GitHub ↗
(req *plugin.GenerateRequest, options *opts.Options, structs []Struct)

Source from the content-addressed store, hash-verified

182}
183
184func buildQueries(req *plugin.GenerateRequest, options *opts.Options, structs []Struct) ([]Query, error) {
185 qs := make([]Query, 0, len(req.Queries))
186 for _, query := range req.Queries {
187 if query.Name == "" {
188 continue
189 }
190 if query.Cmd == "" {
191 continue
192 }
193
194 var constantName string
195 if options.EmitExportedQueries {
196 constantName = sdk.Title(query.Name)
197 } else {
198 constantName = sdk.LowerTitle(query.Name)
199 }
200
201 comments := query.Comments
202 if options.EmitSqlAsComment {
203 if len(comments) == 0 {
204 comments = append(comments, query.Name)
205 }
206 comments = append(comments, " ")
207 scanner := bufio.NewScanner(strings.NewReader(query.Text))
208 for scanner.Scan() {
209 line := scanner.Text()
210 comments = append(comments, " "+line)
211 }
212 if err := scanner.Err(); err != nil {
213 return nil, err
214 }
215 }
216
217 gq := Query{
218 Cmd: query.Cmd,
219 ConstantName: constantName,
220 FieldName: sdk.LowerTitle(query.Name) + "Stmt",
221 MethodName: query.Name,
222 SourceName: query.Filename,
223 SQL: query.Text,
224 Comments: comments,
225 Table: query.InsertIntoTable,
226 }
227 sqlpkg := parseDriver(options.SqlPackage)
228
229 qpl := int(*options.QueryParameterLimit)
230
231 if len(query.Params) == 1 && qpl != 0 {
232 p := query.Params[0]
233 gq.Arg = QueryValue{
234 Name: escape(paramName(p)),
235 DBName: p.Column.GetName(),
236 Typ: goType(req, options, p.Column),
237 SQLDriver: sqlpkg,
238 Column: p.Column,
239 }
240 } else if len(query.Params) >= 1 {
241 var cols []goColumn

Callers 1

GenerateFunction · 0.85

Calls 15

TitleFunction · 0.92
LowerTitleFunction · 0.92
SameTableNameFunction · 0.92
parseDriverFunction · 0.85
escapeFunction · 0.85
paramNameFunction · 0.85
goTypeFunction · 0.85
columnsToStructFunction · 0.85
columnNameFunction · 0.85
putOutColumnsFunction · 0.85
StructNameFunction · 0.85
newGoEmbedFunction · 0.85

Tested by

no test coverage detected