-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
field.go
58 lines (45 loc) · 1.03 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
package chschema
import (
"fmt"
"reflect"
)
const (
customTypeFlag = uint8(1) << iota
)
type Field struct {
Field reflect.StructField
Type reflect.Type
Index []int
GoName string // struct field name, e.g. Id
CHName string // SQL name, .e.g. id
Column Safe // escaped SQL name, e.g. "id"
CHType string
CHDefault Safe
NewColumn NewColumnFunc
appendValue AppenderFunc
IsPK bool
NotNull bool
flags uint8
}
func (f *Field) String() string {
return "field=" + f.GoName
}
func (f *Field) Value(strct reflect.Value) reflect.Value {
return fieldByIndexAlloc(strct, f.Index)
}
func (f *Field) AppendValue(fmter Formatter, b []byte, strct reflect.Value) []byte {
fv, ok := fieldByIndex(strct, f.Index)
if !ok {
return AppendNull(b)
}
if f.appendValue == nil {
return AppendError(b, fmt.Errorf("ch: AppendValue(unsupported %s)", fv.Type()))
}
return f.appendValue(fmter, b, fv)
}
func (f *Field) setFlag(flag uint8) {
f.flags |= flag
}
func (f *Field) hasFlag(flag uint8) bool {
return f.flags&flag != 0
}