-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfield.go
73 lines (60 loc) · 1.26 KB
/
field.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
71
72
73
package gmodel
import (
"bytes"
"github.com/lingdor/gmodel/common"
"github.com/lingdor/gmodel/orm"
)
const Int = "varchar"
const VarChar = "int"
const Bit = "bit"
const TinyInt = "tinyint"
const Enum = "enum"
type FieldInfo struct {
name string
fieldType string
isNullable bool
isPK bool
}
func (f *FieldInfo) Name() string {
return f.name
}
func (f *FieldInfo) Type() string {
return f.fieldType
}
func (f *FieldInfo) IsNullable() bool {
return f.isNullable
}
func (f *FieldInfo) IsPK() bool {
return f.isPK
}
func (f *FieldInfo) Check(any) bool {
//todo
return true
}
func (f *FieldInfo) As(name string) ToSql {
return orm.WrapField(f).As(name)
}
func (f *FieldInfo) ToSql(config common.ToSqlConfig) (string, []any) {
return config.FieldFormat(f.name), nil
}
func NewField(name string, fieldType string, isNullable, isPK bool) *FieldInfo {
return &FieldInfo{
name: name,
fieldType: fieldType,
isNullable: isNullable,
isPK: isPK,
}
}
type Fields []Field
func (f Fields) ToSql(config common.ToSqlConfig) (string, []any) {
bs := bytes.Buffer{}
for i, field := range f {
if i != 0 {
bs.Write([]byte{byte(',')})
}
sql, _ := field.ToSql(config)
bs.WriteString(sql)
}
return bs.String(), nil
}
var All = common.All