forked from slicebit/qb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcompilercontext.go
70 lines (58 loc) · 1.91 KB
/
compilercontext.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
package qb
// NewCompilerContext initialize a new compiler context
func NewCompilerContext(dialect Dialect) Context {
return &CompilerContext{
dialect: dialect,
compiler: dialect.GetCompiler(),
binds: []interface{}{},
}
}
// CompilerContext is a data structure passed to all the Compiler visit
// functions. It contains the bindings, links to the Dialect and Compiler
// being used, and some contextual informations that can be used by the
// compiler functions to communicate during the compilation.
type CompilerContext struct {
binds []interface{}
defaultTableName string
inSubQuery bool
dialect Dialect
compiler Compiler
}
// Compiler returns the compiler in the context
func (ctx *CompilerContext) Compiler() Compiler {
return ctx.compiler
}
// Dialect returns the dialect in the context
func (ctx *CompilerContext) Dialect() Dialect {
return ctx.dialect
}
// Binds returns the binds registered to the context
func (ctx *CompilerContext) Binds() []interface{} {
return ctx.binds
}
// ClearBinds clears all the binds that are registered to the context
func (ctx *CompilerContext) ClearBinds() {
ctx.binds = []interface{}{}
}
// AddBinds registers new binds to the context
func (ctx *CompilerContext) AddBinds(binds ...interface{}) {
for i := 0; i < len(binds); i++ {
ctx.binds = append(ctx.binds, binds[i])
}
}
// DefaultTableName returns the default table name registered to the context
func (ctx *CompilerContext) DefaultTableName() string {
return ctx.defaultTableName
}
// SetDefaultTableName sets the default table name in context
func (ctx *CompilerContext) SetDefaultTableName(name string) {
ctx.defaultTableName = name
}
// InSubQuery returns if InSubQuery is enabled
func (ctx *CompilerContext) InSubQuery() bool {
return ctx.inSubQuery
}
// SetInSubQuery sets the inSubQuery in the context
func (ctx *CompilerContext) SetInSubQuery(inSubQuery bool) {
ctx.inSubQuery = inSubQuery
}