-
Notifications
You must be signed in to change notification settings - Fork 0
/
q_collection_ref.go
60 lines (54 loc) · 1.04 KB
/
q_collection_ref.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
package dal
import "fmt"
// CollectionRef points to a collection (e.g. table) in a database
type CollectionRef struct {
Name string
Alias string
Parent *Key
}
//func (v CollectionRef) Name() string {
// return v.Name
//}
//
//func (v CollectionRef) Alias() string {
// return v.Alias
//}
//
//func (v CollectionRef) Parent() *Key {
// return v.Parent
//}
func (v CollectionRef) String() string {
if v.Name != "" {
if v.Parent == nil {
if v.Alias == "" {
return v.Name
} else {
return fmt.Sprintf("%s AS %s", v.Name, v.Alias)
}
}
}
path := v.Path()
if v.Alias == "" {
return path
}
return fmt.Sprintf("%s AS %s", path, v.Alias)
}
func (v CollectionRef) Path() string {
if v.Parent == nil {
return v.Name
}
return v.Parent.String() + "/" + v.Name
}
func NewCollectionRef(name string, alias string, parent *Key) CollectionRef {
if name == "" {
panic("Name is required parameter for NewCollectionRef()")
}
if alias == name {
alias = ""
}
return CollectionRef{
Name: name,
Alias: alias,
Parent: parent,
}
}