This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
schema.go
118 lines (103 loc) · 1.87 KB
/
schema.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package dataset
type Schema struct {
id SchemaID
source string
name string
fields map[FieldID]*SchemaField
order []FieldID
representativeField *FieldID
scene SceneID
dynamic bool
}
func (d *Schema) ID() (i SchemaID) {
if d == nil {
return
}
return d.id
}
func (d *Schema) IDRef() *SchemaID {
if d == nil {
return nil
}
return d.id.Ref()
}
func (d *Schema) Scene() (i SceneID) {
if d == nil {
return
}
return d.scene
}
func (d *Schema) Source() (s string) {
if d == nil {
return
}
return d.source
}
func (d *Schema) Name() string {
if d == nil {
return ""
}
return d.name
}
func (d *Schema) RepresentativeFieldID() *FieldID {
if d == nil {
return nil
}
return d.representativeField
}
func (d *Schema) RepresentativeField() *SchemaField {
if d == nil || d.representativeField == nil {
return nil
}
return d.fields[*d.representativeField]
}
func (d *Schema) Fields() []*SchemaField {
if d == nil || d.order == nil {
return nil
}
fields := make([]*SchemaField, 0, len(d.fields))
for _, id := range d.order {
fields = append(fields, d.fields[id])
}
return fields
}
func (d *Schema) Field(id FieldID) *SchemaField {
if d == nil {
return nil
}
return d.fields[id]
}
func (d *Schema) FieldRef(id *FieldID) *SchemaField {
if d == nil || id == nil {
return nil
}
return d.fields[*id]
}
func (d *Schema) FieldBySource(source string) *SchemaField {
if d == nil {
return nil
}
for _, f := range d.fields {
if f.source == source {
return f
}
}
return nil
}
func (d *Schema) FieldByType(t ValueType) *SchemaField {
if d == nil {
return nil
}
for _, f := range d.fields {
if f.Type() == t {
return f
}
}
return nil
}
func (d *Schema) Dynamic() bool {
return d.dynamic
}
func (u *Schema) Rename(name string) {
u.name = name
}