forked from ulule/loukoum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loukoum.go
102 lines (84 loc) · 2.97 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
package loukoum
import (
"github.com/ulule/loukoum/builder"
"github.com/ulule/loukoum/stmt"
"github.com/ulule/loukoum/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
// 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}
}
// 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.On {
return stmt.NewOn(stmt.NewColumn(left), stmt.NewColumn(right))
}
// Condition is a wrapper to create a new Identifier statement.
func Condition(column string) 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)
}
// 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)
}
// 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))
}