-
Notifications
You must be signed in to change notification settings - Fork 208
/
prepared.go
48 lines (38 loc) · 1.14 KB
/
prepared.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
package goqu
var (
// defaultPrepared is controlled by SetDefaultPrepared
defaultPrepared bool
)
type prepared int
const (
// zero value that defers to defaultPrepared
preparedNoPreference prepared = iota
// explicitly enabled via Prepared(true) on a dataset
preparedEnabled
// explicitly disabled via Prepared(false) on a dataset
preparedDisabled
)
// Bool converts the ternary prepared state into a boolean. If the prepared
// state is preparedNoPreference, the value depends on the last value that
// SetDefaultPrepared was called with which is false by default.
func (p prepared) Bool() bool {
if p == preparedNoPreference {
return defaultPrepared
} else if p == preparedEnabled {
return true
}
return false
}
// preparedFromBool converts a bool from e.g. Prepared(true) into a prepared
// const.
func preparedFromBool(prepared bool) prepared {
if prepared {
return preparedEnabled
}
return preparedDisabled
}
// SetDefaultPrepared controls the default Prepared state of all datasets. If
// set to true, any new dataset will use prepared queries by default.
func SetDefaultPrepared(prepared bool) {
defaultPrepared = prepared
}