-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq_collection_ref.go
69 lines (59 loc) · 1.25 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
61
62
63
64
65
66
67
68
69
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, alias string) CollectionRef {
if name == "" {
panic("Name is required parameter for NewCollectionRef()")
}
if alias == name {
alias = ""
}
return CollectionRef{
name: name,
alias: alias,
}
}
func NewCollectionRef(name, alias string, parent *Key) (collectionRef CollectionRef) {
collectionRef = newCollectionRef(name, alias)
collectionRef.parent = parent
return
}
func NewRootCollectionRef(name, alias string) CollectionRef {
return newCollectionRef(name, alias)
}