-
Notifications
You must be signed in to change notification settings - Fork 2
/
boolean.go
59 lines (49 loc) · 1.01 KB
/
boolean.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
package types
import (
"fmt"
"strings"
"github.com/aodin/sol/dialect"
)
// Provide a nullable boolean for Boolean type default values
var (
internalTrue bool = true
internalFalse bool = false
True = &internalTrue
False = &internalFalse
)
type boolean struct {
BaseType
value *bool
}
var _ Type = boolean{}
func (t boolean) Create(d dialect.Dialect) (string, error) {
compiled, err := t.BaseType.Create(d)
if err != nil {
return "", err
}
if t.value != nil {
compiled += strings.ToUpper(fmt.Sprintf(" DEFAULT %t", *t.value))
}
return compiled, nil
}
// Default will set the default value of the boolean
func (t boolean) Default(value bool) boolean {
if value {
t.value = True
} else {
t.value = False
}
return t
}
func (t boolean) NotNull() boolean {
t.BaseType.NotNull()
return t
}
func (t boolean) Unique() boolean {
t.BaseType.Unique()
return t
}
// Boolean creats a new BOOLEAN datatype
func Boolean() (t boolean) {
return boolean{BaseType: Base("BOOLEAN")}
}