(c *catalog.Catalog, node ast.Node, embeds rewrite.EmbedSet)
| 15 | } |
| 16 | |
| 17 | func (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 | |
| 66 | func ConvertColumn(rel *ast.TableName, c *catalog.Column) *Column { |
| 67 | return &Column{ |
no test coverage detected