This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathproperty.go
62 lines (59 loc) · 2.13 KB
/
property.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
package orient
// OProperty roughly corresponds to OProperty in the Java client.
// It represents a property of a class in OrientDB.
// A property represents the metadata of a field. A field (OField)
// is the actual data of a field in an Document.
type OProperty struct {
Id int32
Name string
Fullname string // Classname.propertyName
Type byte // corresponds to one of the type constants above
NotNull bool
Collate string // is OCollate in Java client
Mandatory bool
Min string
Max string
Regexp string
CustomFields map[string]string
Readonly bool
}
// NewOPropertyFromDocument creates a new OProperty from an Document
// that was created after a load schema call to the OrientDB server.
func NewOPropertyFromDocument(doc *Document) *OProperty {
oprop := &OProperty{}
if fld := doc.GetField("globalId"); fld != nil && fld.Value != nil {
oprop.Id = fld.Value.(int32)
}
if fld := doc.GetField("name"); fld != nil && fld.Value != nil {
oprop.Name = fld.Value.(string)
}
if fld := doc.GetField("type"); fld != nil && fld.Value != nil {
oprop.Type = byte(fld.Value.(int32))
}
if fld := doc.GetField("notNull"); fld != nil && fld.Value != nil {
oprop.NotNull = fld.Value.(bool)
}
if fld := doc.GetField("collate"); fld != nil && fld.Value != nil {
oprop.Collate = fld.Value.(string)
}
if fld := doc.GetField("mandatory"); fld != nil && fld.Value != nil {
oprop.Mandatory = fld.Value.(bool)
}
if fld := doc.GetField("min"); fld != nil && fld.Value != nil {
oprop.Min = fld.Value.(string)
}
if fld := doc.GetField("max"); fld != nil && fld.Value != nil {
oprop.Max = fld.Value.(string)
}
if fld := doc.GetField("regexp"); fld != nil && fld.Value != nil {
oprop.Regexp = fld.Value.(string)
}
if fld := doc.GetField("customFields"); fld != nil && fld.Value != nil {
oprop.CustomFields = make(map[string]string)
panic("customFields handling NOT IMPLEMENTED: Don't know what data structure is coming back from the server (need example)")
}
if fld := doc.GetField("readonly"); fld != nil && fld.Value != nil {
oprop.Readonly = fld.Value.(bool)
}
return oprop
}