forked from solher/arangolite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collection.go
117 lines (94 loc) · 2.82 KB
/
collection.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
package requests
import (
"encoding/json"
"fmt"
)
// CreateCollection creates a collection in database.
type CreateCollection struct {
JournalSize int `json:"journalSize,omitempty"`
KeyOptions map[string]interface{} `json:"keyOptions,omitempty"`
Name string `json:"name"`
WaitForSync bool `json:"waitForSync,omitempty"`
DoCompact bool `json:"doCompact,omitempty"`
IsVolatile bool `json:"isVolatile,omitempty"`
ShardKeys []string `json:"shardKeys,omitempty"`
NumberOfShards int `json:"numberOfShards,omitempty"`
IsSystem bool `json:"isSystem,omitempty"`
Type int `json:"type,omitempty"`
IndexBuckets int `json:"indexBuckets,omitempty"`
}
func (r *CreateCollection) Path() string {
return "/_api/collection"
}
func (r *CreateCollection) Method() string {
return "POST"
}
func (r *CreateCollection) Generate() []byte {
m, _ := json.Marshal(r)
return m
}
// DropCollection deletes a collection in database.
type DropCollection struct {
Name string
}
func (r *DropCollection) Path() string {
return fmt.Sprintf("/_api/collection/%s", r.Name)
}
func (r *DropCollection) Method() string {
return "DELETE"
}
func (r *DropCollection) Generate() []byte {
return nil
}
// TruncateCollection deletes a collection in database.
type TruncateCollection struct {
Name string
}
func (r *TruncateCollection) Path() string {
return fmt.Sprintf("/_api/collection/%s/truncate", r.Name)
}
func (r *TruncateCollection) Method() string {
return "PUT"
}
func (r *TruncateCollection) Generate() []byte {
return nil
}
type CollectionInfo struct {
Id string `json:"id"`
Name string `json:"name"`
IsSystem bool `json:"isSystem"`
Status int `json:"status"`
Type int `json:"type"`
}
type CollectionInfoList struct {
Collections []CollectionInfo `json:"collections"`
Error bool `json:"error"`
Code int `json:"code"`
}
// ListCollections lists all collections from the current DB
type ListCollections struct {
includeSystem bool
}
func (c *ListCollections) Path() string {
return fmt.Sprintf("/_api/collection?excludeSystem=%v", !c.includeSystem)
}
func (c *ListCollections) Method() string {
return "GET"
}
func (c *ListCollections) Generate() []byte {
return nil
}
// CollectionInfo gets information about the collection
type GetCollectionInfo struct {
CollectionName string
IncludeSystem bool
}
func (c *GetCollectionInfo) Path() string {
return fmt.Sprintf("/_api/collection/%s?excludeSystem=%v", c.CollectionName, !c.IncludeSystem)
}
func (c *GetCollectionInfo) Method() string {
return "GET"
}
func (c *GetCollectionInfo) Generate() []byte {
return nil
}