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

Function parseRelation

internal/compiler/compat.go:28–90  ·  view source on GitHub ↗
(node ast.Node)

Source from the content-addressed store, hash-verified

26}
27
28func parseRelation(node ast.Node) (*Relation, error) {
29 switch n := node.(type) {
30 case *ast.Boolean:
31 if n == nil {
32 return nil, fmt.Errorf("unexpected nil in %T node", n)
33 }
34 return &Relation{Name: "bool"}, nil
35
36 case *ast.List:
37 if n == nil {
38 return nil, fmt.Errorf("unexpected nil in %T node", n)
39 }
40 parts := stringSlice(n)
41 switch len(parts) {
42 case 1:
43 return &Relation{
44 Name: parts[0],
45 }, nil
46 case 2:
47 return &Relation{
48 Schema: parts[0],
49 Name: parts[1],
50 }, nil
51 case 3:
52 return &Relation{
53 Catalog: parts[0],
54 Schema: parts[1],
55 Name: parts[2],
56 }, nil
57 default:
58 return nil, fmt.Errorf("invalid name: %s", astutils.Join(n, "."))
59 }
60
61 case *ast.RangeVar:
62 if n == nil {
63 return nil, fmt.Errorf("unexpected nil in %T node", n)
64 }
65 name := Relation{}
66 if n.Catalogname != nil {
67 name.Catalog = *n.Catalogname
68 }
69 if n.Schemaname != nil {
70 name.Schema = *n.Schemaname
71 }
72 if n.Relname != nil {
73 name.Name = *n.Relname
74 }
75 return &name, nil
76
77 case *ast.TypeName:
78 if n == nil {
79 return nil, fmt.Errorf("unexpected nil in %T node", n)
80 }
81 if n.Names != nil {
82 return parseRelation(n.Names)
83 } else {
84 return &Relation{Name: n.Name}, nil
85 }

Callers 2

ParseTableNameFunction · 0.70
ParseTypeNameFunction · 0.70

Calls 2

JoinFunction · 0.92
stringSliceFunction · 0.70

Tested by

no test coverage detected