MCPcopy Index your code
hub / github.com/sqlc-dev/sqlc / buildQueryCatalog

Method buildQueryCatalog

internal/compiler/query_catalog.go:17–64  ·  view source on GitHub ↗
(c *catalog.Catalog, node ast.Node, embeds rewrite.EmbedSet)

Source from the content-addressed store, hash-verified

15}
16
17func (comp *Compiler) buildQueryCatalog(c *catalog.Catalog, node ast.Node, embeds rewrite.EmbedSet) (*QueryCatalog, error) {
18 var with *ast.WithClause
19 switch n := node.(type) {
20 case *ast.DeleteStmt:
21 with = n.WithClause
22 case *ast.InsertStmt:
23 with = n.WithClause
24 case *ast.UpdateStmt:
25 with = n.WithClause
26 case *ast.SelectStmt:
27 with = n.WithClause
28 default:
29 with = nil
30 }
31 qc := &QueryCatalog{catalog: c, ctes: map[string]*Table{}, embeds: embeds}
32 if with != nil {
33 for _, item := range with.Ctes.Items {
34 if cte, ok := item.(*ast.CommonTableExpr); ok {
35 cols, err := comp.outputColumns(qc, cte.Ctequery)
36 if err != nil {
37 return nil, err
38 }
39 var names []string
40 if cte.Aliascolnames != nil {
41 for _, item := range cte.Aliascolnames.Items {
42 if val, ok := item.(*ast.String); ok {
43 names = append(names, val.Str)
44 } else {
45 names = append(names, "")
46 }
47 }
48 }
49 rel := &ast.TableName{Name: *cte.Ctename}
50 for i := range cols {
51 cols[i].Table = rel
52 if len(names) > i {
53 cols[i].Name = names[i]
54 }
55 }
56 qc.ctes[*cte.Ctename] = &Table{
57 Rel: rel,
58 Columns: cols,
59 }
60 }
61 }
62 }
63 return qc, nil
64}
65
66func ConvertColumn(rel *ast.TableName, c *catalog.Column) *Column {
67 return &Column{

Callers 2

OutputColumnsMethod · 0.95
_analyzeQueryMethod · 0.95

Calls 1

outputColumnsMethod · 0.95

Tested by

no test coverage detected