-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement.go
51 lines (42 loc) · 1.51 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
package sqext
import (
sq "github.com/Masterminds/squirrel"
"github.com/lann/builder"
)
// StatementBuilderType is the type of StatementBuilder.
type StatementBuilderType builder.Builder
// PlaceholderFormat sets the PlaceholderFormat field for any child builders.
func (b StatementBuilderType) PlaceholderFormat(f sq.PlaceholderFormat) StatementBuilderType {
return builder.Set(b, "PlaceholderFormat", f).(StatementBuilderType)
}
// Aux returns a AuxBuilder for this StatementBuilderType.
func (b StatementBuilderType) Aux(stmt sq.Sqlizer) AuxBuilder {
return AuxBuilder(b).Statement(stmt)
}
// CTE returns a CTEBuilder for this StatementBuilderType.
func (b StatementBuilderType) CTE(auxStmts ...AuxBuilder) CTEBuilder {
return CTEBuilder(b).AuxStatements(auxStmts...)
}
// StatementBuilder is a parent builder for other builders.
var StatementBuilder = StatementBuilderType(builder.EmptyBuilder).PlaceholderFormat(sq.Question)
// Aux returns a new AuxBuilder with a given sq.Sqlizer.
//
// See AuxBuilder.Statement.
func Aux(stmt sq.Sqlizer) AuxBuilder {
return StatementBuilder.Aux(stmt)
}
// CTE returns a new CTEBulder with a list of given auxillary statements.
//
// See AuxBuilder.Statments.
func CTE(auxStmts ...AuxBuilder) CTEBuilder {
return StatementBuilder.CTE(auxStmts...)
}
func setRunWith(b interface{}, runner sq.BaseRunner) interface{} {
switch r := runner.(type) {
case sq.StdSqlCtx:
runner = sq.WrapStdSqlCtx(r)
case sq.StdSql:
runner = sq.WrapStdSql(r)
}
return builder.Set(b, "RunWith", runner)
}