-
Notifications
You must be signed in to change notification settings - Fork 13
/
loukoum.go
166 lines (136 loc) · 4.95 KB
/
loukoum.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package loukoum
import (
"github.com/ulule/loukoum/v3/builder"
"github.com/ulule/loukoum/v3/stmt"
"github.com/ulule/loukoum/v3/types"
)
const (
// InnerJoin is used for "INNER JOIN" in join statement.
InnerJoin = types.InnerJoin
// LeftJoin is used for "LEFT JOIN" in join statement.
LeftJoin = types.LeftJoin
// RightJoin is used for "RIGHT JOIN" in join statement.
RightJoin = types.RightJoin
// LeftOuterJoin is used for "LEFT OUTER JOIN" in join statement.
LeftOuterJoin = types.LeftOuterJoin
// RightOuterJoin is used for "RIGHT OUTER JOIN" in join statement.
RightOuterJoin = types.RightOuterJoin
// Asc is used for "ORDER BY" statement.
Asc = types.Asc
// Desc is used for "ORDER BY" statement.
Desc = types.Desc
)
// Map is a key/value map.
type Map = types.Map
// Pair takes a key and its related value and returns a Pair.
func Pair(key, value interface{}) types.Pair {
return types.Pair{Key: key, Value: value}
}
// Value is a wrapper to create a new Value expression.
func Value(value interface{}) stmt.Value {
return stmt.NewValue(value)
}
// Select starts a SelectBuilder using the given columns.
func Select(columns ...interface{}) builder.Select {
return builder.NewSelect().Columns(columns...)
}
// Column is a wrapper to create a new Column statement.
func Column(name string) stmt.Column {
return stmt.NewColumn(name)
}
// Table is a wrapper to create a new Table statement.
func Table(name string) stmt.Table {
return stmt.NewTable(name)
}
// On is a wrapper to create a new On statement.
func On(left string, right string) stmt.OnClause {
return stmt.NewOnClause(stmt.NewColumn(left), stmt.NewColumn(right))
}
// AndOn is a wrapper to create a new On statement using an infix expression.
func AndOn(left stmt.OnExpression, right stmt.OnExpression) stmt.OnExpression {
return stmt.NewInfixOnExpression(left, stmt.NewLogicalOperator(types.And), right)
}
// OrOn is a wrapper to create a new On statement using an infix expression.
func OrOn(left stmt.OnExpression, right stmt.OnExpression) stmt.OnExpression {
return stmt.NewInfixOnExpression(left, stmt.NewLogicalOperator(types.Or), right)
}
// Condition is a wrapper to create a new Identifier statement.
func Condition(column interface{}) stmt.Identifier {
return stmt.NewIdentifier(column)
}
// Order is a wrapper to create a new Order statement.
func Order(column string, option ...types.OrderType) stmt.Order {
order := types.Asc
if len(option) > 0 {
order = option[0]
}
return stmt.NewOrder(column, order)
}
// Offset is a wrapper to create a new Offset statement.
func Offset(start int64) stmt.Offset {
return stmt.NewOffset(start)
}
// Limit is a wrapper to create a new Limit statement.
func Limit(count int64) stmt.Limit {
return stmt.NewLimit(count)
}
// And is a wrapper to create a new InfixExpression statement.
func And(left stmt.Expression, right stmt.Expression) stmt.InfixExpression {
return stmt.NewInfixExpression(left, stmt.NewLogicalOperator(types.And), right)
}
// Or is a wrapper to create a new InfixExpression statement.
func Or(left stmt.Expression, right stmt.Expression) stmt.InfixExpression {
return stmt.NewInfixExpression(left, stmt.NewLogicalOperator(types.Or), right)
}
// Raw is a wrapper to create a new Raw expression.
func Raw(value string) stmt.Raw {
return stmt.NewRaw(value)
}
// Exists is a wrapper to create a new Exists expression.
func Exists(value interface{}) stmt.Exists {
return stmt.NewExists(value)
}
// NotExists is a wrapper to create a new NotExists expression.
func NotExists(value interface{}) stmt.NotExists {
return stmt.NewNotExists(value)
}
// Count is a wrapper to create a new Count expression.
func Count(value string) stmt.Count {
return stmt.NewCount(value)
}
// Max is a wrapper to create a new Max expression.
func Max(value string) stmt.Max {
return stmt.NewMax(value)
}
// Min is a wrapper to create a new Min expression.
func Min(value string) stmt.Min {
return stmt.NewMin(value)
}
// Sum is a wrapper to create a new Sum expression.
func Sum(value string) stmt.Sum {
return stmt.NewSum(value)
}
// With is a wrapper to create a new WithQuery statement.
func With(name string, value interface{}) stmt.WithQuery {
return stmt.NewWithQuery(name, value)
}
// Insert starts an InsertBuilder using the given table as into clause.
func Insert(into interface{}) builder.Insert {
return builder.NewInsert().Into(into)
}
// Delete starts a DeleteBuilder using the given table as from clause.
func Delete(from interface{}) builder.Delete {
return builder.NewDelete().From(from)
}
// Update starts an Update builder using the given table.
func Update(table interface{}) builder.Update {
return builder.NewUpdate(table)
}
// DoNothing is a wrapper to create a new ConflictNoAction statement.
func DoNothing() stmt.ConflictNoAction {
return stmt.NewConflictNoAction()
}
// DoUpdate is a wrapper to create a new ConflictUpdateAction statement.
func DoUpdate(args ...interface{}) stmt.ConflictUpdateAction {
return stmt.NewConflictUpdateAction(builder.ToSet(args))
}