-
-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathmods_values.go
More file actions
49 lines (44 loc) · 1.42 KB
/
Copy pathmods_values.go
File metadata and controls
49 lines (44 loc) · 1.42 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
package parser
import (
"fmt"
pg "github.com/pganalyze/pg_query_go/v6"
"github.com/stephenafamo/bob/internal"
)
func (w *walker) modValuesStatement(stmt *pg.Node_SelectStmt, info nodeInfo) {
if orderInfo, ok := info.children["SortClause"]; ok {
w.editRules = append(w.editRules, internal.RecordPoints(
int(orderInfo.start),
int(orderInfo.end)-1,
func(start, end int) error {
fmt.Fprintf(w.mods, "q.AppendOrder(EXPR.subExpr(%d, %d))\n", start, end)
return nil
},
)...)
}
if limitInfo, ok := info.children["LimitCount"]; ok {
w.editRules = append(w.editRules, internal.RecordPoints(
int(limitInfo.start),
int(limitInfo.end)-1,
func(start, end int) error {
switch stmt.SelectStmt.LimitOption {
case pg.LimitOption_LIMIT_OPTION_COUNT:
fmt.Fprintf(w.mods, "q.SetLimit(EXPR.subExpr(%d, %d))\n", start, end)
case pg.LimitOption_LIMIT_OPTION_WITH_TIES:
w.imports = append(w.imports, []string{"github.com/stephenafamo/bob/clause"})
fmt.Fprintf(w.mods, "q.SetFetch(clause.Fetch{Count: EXPR.subExpr(%d, %d), WithTies: true})\n", start, end)
}
return nil
},
)...)
}
if offsetInfo, ok := info.children["LimitOffset"]; ok {
w.editRules = append(w.editRules, internal.RecordPoints(
int(offsetInfo.start),
int(offsetInfo.end)-1,
func(start, end int) error {
fmt.Fprintf(w.mods, "q.SetOffset(EXPR.subExpr(%d, %d))\n", start, end)
return nil
},
)...)
}
}