forked from Masterminds/squirrel
-
Notifications
You must be signed in to change notification settings - Fork 38
/
statement.go
87 lines (72 loc) · 2.42 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
package sqrl
// StatementBuilderType is the type of StatementBuilder.
type StatementBuilderType struct {
placeholderFormat PlaceholderFormat
runWith BaseRunner
}
// Select returns a SelectBuilder for this StatementBuilder.
func (b StatementBuilderType) Select(columns ...string) *SelectBuilder {
return NewSelectBuilder(b).Columns(columns...)
}
// Insert returns a InsertBuilder for this StatementBuilder.
func (b StatementBuilderType) Insert(into string) *InsertBuilder {
return NewInsertBuilder(b).Into(into)
}
// Update returns a UpdateBuilder for this StatementBuilder.
func (b StatementBuilderType) Update(table string) *UpdateBuilder {
return NewUpdateBuilder(b).Table(table)
}
// Delete returns a DeleteBuilder for this StatementBuilder.
func (b StatementBuilderType) Delete(what ...string) *DeleteBuilder {
return NewDeleteBuilder(b).What(what...)
}
// PlaceholderFormat sets the PlaceholderFormat field for any child builders.
func (b StatementBuilderType) PlaceholderFormat(f PlaceholderFormat) StatementBuilderType {
b.placeholderFormat = f
return b
}
// RunWith sets the RunWith field for any child builders.
func (b StatementBuilderType) RunWith(runner BaseRunner) StatementBuilderType {
b.runWith = wrapRunner(runner)
return b
}
// StatementBuilder is a basic statement builder, holds global configuration options
// like placeholder format or SQL runner
var StatementBuilder = StatementBuilderType{placeholderFormat: Question}
// Select returns a new SelectBuilder, optionally setting some result columns.
//
// See SelectBuilder.Columns.
func Select(columns ...string) *SelectBuilder {
return StatementBuilder.Select(columns...)
}
// Insert returns a new InsertBuilder with the given table name.
//
// See InsertBuilder.Into.
func Insert(into string) *InsertBuilder {
return StatementBuilder.Insert(into)
}
// Update returns a new UpdateBuilder with the given table name.
//
// See UpdateBuilder.Table.
func Update(table string) *UpdateBuilder {
return StatementBuilder.Update(table)
}
// Delete returns a new DeleteBuilder for given table names.
//
// See DeleteBuilder.Table.
func Delete(what ...string) *DeleteBuilder {
return StatementBuilder.Delete(what...)
}
// Case returns a new CaseBuilder
// "what" represents case value
func Case(what ...interface{}) *CaseBuilder {
b := &CaseBuilder{}
switch len(what) {
case 0:
case 1:
b = b.what(what[0])
default:
b = b.what(newPart(what[0], what[1:]...))
}
return b
}