forked from fluge/squirrel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement.go
136 lines (110 loc) · 3.91 KB
/
statement.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
package squirrel
import (
"fmt"
"github.com/lann/builder"
)
// StatementBuilderType is the type of StatementBuilder.
type StatementBuilderType builder.Builder
// Select returns a SelectBuilder for this StatementBuilderType.
func (b StatementBuilderType) Select(columns ...string) SelectCondition {
return SelectBuilder(b).Columns(columns...)
}
func (b StatementBuilderType) Count(columns string) SelectCondition {
str := fmt.Sprintf("COUNT(%s)", columns)
return SelectBuilder(b).Columns(str)
}
// Insert returns a InsertBuilder for this StatementBuilderType.
func (b StatementBuilderType) Insert(into string) InsertCondition {
return InsertBuilder(b).Into(into)
}
// Update returns a UpdateBuilder for this StatementBuilderType.
func (b StatementBuilderType) Update(table string) UpdateCondition {
return UpdateBuilder(b).Table(table)
}
// Delete returns a DeleteBuilder for this StatementBuilderType.
func (b StatementBuilderType) Delete(from string) DeleteCondition {
return DeleteBuilder(b).From(from)
}
func (b StatementBuilderType) Where(pred interface{}, args ...interface{}) WhereConditions {
return WhereBuilder(b).Where(pred, args...)
}
func (b StatementBuilderType) Condition() WhereConditions {
return WhereBuilder(b).Where("")
}
func (b StatementBuilderType) Join(join string, rest ...interface{}) JoinCondition {
return JoinBuilder(b).Join(join, rest...)
}
func (b StatementBuilderType) JoinClause(pred interface{}, args ...interface{}) JoinCondition {
return JoinBuilder(b).JoinClause(pred, args...)
}
func (b StatementBuilderType) LeftJoin(join string, rest ...interface{}) JoinCondition {
return JoinBuilder(b).LeftJoin(join, rest...)
}
func (b StatementBuilderType) RightJoin(join string, rest ...interface{}) JoinCondition {
return JoinBuilder(b).RightJoin(join, rest...)
}
// PlaceholderFormat sets the PlaceholderFormat field for any child builders.
func (b StatementBuilderType) PlaceholderFormat(f PlaceholderFormat) StatementBuilderType {
return builder.Set(b, "PlaceholderFormat", f).(StatementBuilderType)
}
// StatementBuilder is a parent builder for other builders, e.g. SelectBuilder.
var StatementBuilder = StatementBuilderType(builder.EmptyBuilder).PlaceholderFormat(Question)
// Select returns a new SelectBuilder, optionally setting some result columns.
//
// See SelectBuilder.Columns.
func Select(columns ...string) SelectCondition {
return StatementBuilder.Select(columns...)
}
// Insert returns a new InsertBuilder with the given table name.
//
// See InsertBuilder.Into.
func Insert(into string) InsertCondition {
return StatementBuilder.Insert(into)
}
// Update returns a new UpdateBuilder with the given table name.
//
// See UpdateBuilder.Table.
func Update(table string) UpdateCondition {
return StatementBuilder.Update(table)
}
// Delete returns a new DeleteBuilder with the given table name.
//
// See DeleteBuilder.Table.
func Delete(from string) DeleteCondition {
return StatementBuilder.Delete(from)
}
//新增的where方法
func Where(pred interface{}, args ...interface{}) WhereConditions {
return StatementBuilder.Where(pred, args...)
}
func Condition() WhereConditions {
return StatementBuilder.Condition()
}
//新增的join方法
func Join(join string, rest ...interface{}) JoinCondition {
return StatementBuilder.Join(join, rest...)
}
func JoinClause(pred interface{}, args ...interface{}) JoinCondition {
return StatementBuilder.JoinClause(pred, args...)
}
func LeftJoin(join string, rest ...interface{}) JoinCondition {
return StatementBuilder.LeftJoin(join, rest...)
}
func RightJoin(join string, rest ...interface{}) JoinCondition {
return StatementBuilder.RightJoin(join, rest...)
}
//// Case returns a new CaseBuilder
//// "what" represents case value
//func Case(what ...interface{}) CaseBuilder {
// b := CaseBuilder(builder.EmptyBuilder)
//
// switch len(what) {
// case 0:
// case 1:
// b = b.what(what[0])
// default:
// b = b.what(newPart(what[0], what[1:]...))
//
// }
// return b
//}