-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdml.go
More file actions
101 lines (93 loc) · 2.77 KB
/
dml.go
File metadata and controls
101 lines (93 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package ast
// Select represents a SELECT statement
type Select struct {
Distinct bool
Columns []Expression
From []TableReference
Where Expression
GroupBy []Expression
Having Expression
OrderBy []OrderByExpression
Limit *int64
Offset *int64
}
func (s *Select) statementNode() {}
func (s Select) TokenLiteral() string { return "SELECT" }
func (s Select) Children() []Node {
children := make([]Node, 0)
children = append(children, nodifyExpressions(s.Columns)...)
for _, from := range s.From {
from := from // G601: Create local copy to avoid memory aliasing
children = append(children, &from)
}
if s.Where != nil {
children = append(children, s.Where)
}
children = append(children, nodifyExpressions(s.GroupBy)...)
if s.Having != nil {
children = append(children, s.Having)
}
for _, orderBy := range s.OrderBy {
orderBy := orderBy // G601: Create local copy to avoid memory aliasing
children = append(children, &orderBy)
}
return children
}
// Insert represents an INSERT statement
type Insert struct {
Table TableReference
Columns []Expression
Values [][]Expression
ReturningClause []Expression
}
func (i *Insert) statementNode() {}
func (i Insert) TokenLiteral() string { return "INSERT" }
func (i Insert) Children() []Node {
children := make([]Node, 0)
children = append(children, &i.Table)
children = append(children, nodifyExpressions(i.Columns)...)
for _, row := range i.Values {
children = append(children, nodifyExpressions(row)...)
}
children = append(children, nodifyExpressions(i.ReturningClause)...)
return children
}
// Delete represents a DELETE statement
type Delete struct {
Table TableReference
Where Expression
ReturningClause []Expression
}
func (d *Delete) statementNode() {}
func (d Delete) TokenLiteral() string { return "DELETE" }
func (d Delete) Children() []Node {
children := make([]Node, 0)
children = append(children, &d.Table)
if d.Where != nil {
children = append(children, d.Where)
}
children = append(children, nodifyExpressions(d.ReturningClause)...)
return children
}
// Update represents an UPDATE statement
type Update struct {
Table TableReference
Updates []UpdateExpression
Where Expression
ReturningClause []Expression
}
func (u *Update) statementNode() {}
func (u Update) TokenLiteral() string { return "UPDATE" }
func (u Update) Children() []Node {
children := make([]Node, 0)
children = append(children, &u.Table)
for _, update := range u.Updates {
update := update // G601: Create local copy to avoid memory aliasing
children = append(children, &update)
}
if u.Where != nil {
children = append(children, u.Where)
}
children = append(children, nodifyExpressions(u.ReturningClause)...)
return children
}