-
Notifications
You must be signed in to change notification settings - Fork 37
/
qm.go
96 lines (76 loc) · 2.49 KB
/
qm.go
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
package um
import (
"github.com/stephenafamo/bob"
"github.com/stephenafamo/bob/clause"
"github.com/stephenafamo/bob/dialect/psql/dialect"
"github.com/stephenafamo/bob/internal"
"github.com/stephenafamo/bob/mods"
)
func With(name string, columns ...string) dialect.CTEChain[*dialect.UpdateQuery] {
return dialect.With[*dialect.UpdateQuery](name, columns...)
}
func Recursive(r bool) bob.Mod[*dialect.UpdateQuery] {
return mods.Recursive[*dialect.UpdateQuery](r)
}
func Only() bob.Mod[*dialect.UpdateQuery] {
return mods.QueryModFunc[*dialect.UpdateQuery](func(u *dialect.UpdateQuery) {
u.Only = true
})
}
func Table(name any) bob.Mod[*dialect.UpdateQuery] {
return mods.QueryModFunc[*dialect.UpdateQuery](func(u *dialect.UpdateQuery) {
u.Table = clause.Table{
Expression: name,
}
})
}
func TableAs(name any, alias string) bob.Mod[*dialect.UpdateQuery] {
return mods.QueryModFunc[*dialect.UpdateQuery](func(u *dialect.UpdateQuery) {
u.Table = clause.Table{
Expression: name,
Alias: alias,
}
})
}
func Set(sets ...bob.Expression) bob.Mod[*dialect.UpdateQuery] {
return mods.QueryModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
q.Set.Set = append(q.Set.Set, internal.ToAnySlice(sets)...)
})
}
func SetCol(from string) mods.Set[*dialect.UpdateQuery] {
return mods.Set[*dialect.UpdateQuery]([]string{from})
}
func From(table any) dialect.FromChain[*dialect.UpdateQuery] {
return dialect.From[*dialect.UpdateQuery](table)
}
func FromFunction(funcs ...*dialect.Function) dialect.FromChain[*dialect.UpdateQuery] {
var table any
if len(funcs) == 1 {
table = funcs[0]
}
if len(funcs) > 1 {
table = dialect.Functions(funcs)
}
return dialect.From[*dialect.UpdateQuery](table)
}
func InnerJoin(e any) dialect.JoinChain[*dialect.UpdateQuery] {
return dialect.InnerJoin[*dialect.UpdateQuery](e)
}
func LeftJoin(e any) dialect.JoinChain[*dialect.UpdateQuery] {
return dialect.LeftJoin[*dialect.UpdateQuery](e)
}
func RightJoin(e any) dialect.JoinChain[*dialect.UpdateQuery] {
return dialect.RightJoin[*dialect.UpdateQuery](e)
}
func FullJoin(e any) dialect.JoinChain[*dialect.UpdateQuery] {
return dialect.FullJoin[*dialect.UpdateQuery](e)
}
func CrossJoin(e any) bob.Mod[*dialect.UpdateQuery] {
return dialect.CrossJoin[*dialect.UpdateQuery](e)
}
func Where(e bob.Expression) mods.Where[*dialect.UpdateQuery] {
return mods.Where[*dialect.UpdateQuery]{E: e}
}
func Returning(clauses ...any) bob.Mod[*dialect.UpdateQuery] {
return mods.Returning[*dialect.UpdateQuery](clauses)
}