-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxfieldvarchar.go
54 lines (45 loc) · 1.39 KB
/
xfieldvarchar.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
package xdominion
import (
"fmt"
)
type XFieldVarChar struct {
Name string
Size int
Constraints XConstraints
}
// creates the name of the field with its type (to create the table)
func (f XFieldVarChar) CreateField(prepend string, DB string, ifText *bool) string {
ftype := " varchar(" + fmt.Sprint(f.Size) + ")"
extra := ""
if f.Constraints != nil {
extra = f.Constraints.CreateConstraints(prepend, f.Name, DB)
}
return prepend + f.Name + ftype + extra
}
// creates a string representation of the value of the field for insert/update and queries where
func (f XFieldVarChar) CreateValue(v interface{}, table string, DB string, id string) string {
return "'" + fmt.Sprint(v) + "'"
}
// creates the sequence used by the field (only autoincrement fields)
func (f XFieldVarChar) CreateSequence(table string) string {
return ""
}
// creates the index used by the field (normal, unique, multi, multi unique)
func (f XFieldVarChar) CreateIndex(table string, id string, DB string) []string {
if f.Constraints != nil {
return f.Constraints.CreateIndex(table, id, f.Name, DB)
}
return []string{}
}
// gets the name of the field
func (f XFieldVarChar) GetName() string {
return f.Name
}
// gets the type of the field
func (f XFieldVarChar) GetType() int {
return XField_VarChar
}
// gets the checks of the field
func (f XFieldVarChar) GetConstraints() XConstraints {
return f.Constraints
}