/
zz_generated_collection.go
276 lines (228 loc) · 8.94 KB
/
zz_generated_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// Code generated by github.com/jim-minter/go-cosmosdb, DO NOT EDIT.
package cosmosdb
import (
"net/http"
)
// Collection represents a collection
type Collection struct {
ID string `json:"id,omitempty"`
ResourceID string `json:"_rid,omitempty"`
Timestamp int `json:"_ts,omitempty"`
Self string `json:"_self,omitempty"`
ETag string `json:"_etag,omitempty"`
Documents string `json:"_docs,omitempty"`
StoredProcedures string `json:"_sprocs,omitempty"`
Triggers string `json:"_triggers,omitempty"`
UserDefinedFunctions string `json:"_udfs,omitempty"`
Conflicts string `json:"_conflicts,omitempty"`
IndexingPolicy *IndexingPolicy `json:"indexingPolicy,omitempty"`
PartitionKey *PartitionKey `json:"partitionKey,omitempty"`
ConflictResolutionPolicy *ConflictResolutionPolicy `json:"conflictResolutionPolicy,omitempty"`
GeospatialConfig *GeospatialConfig `json:"geospatialConfig,omitempty"`
}
// IndexingPolicy represents an indexing policy
type IndexingPolicy struct {
Automatic bool `json:"automatic,omitempty"`
IndexingMode IndexingPolicyMode `json:"indexingMode,omitempty"`
IncludedPaths []IncludedPath `json:"includedPaths,omitempty"`
ExcludedPaths []IncludedPath `json:"excludedPaths,omitempty"`
}
// IndexingPolicyMode represents an indexing policy mode
type IndexingPolicyMode string
// IndexingPolicyMode constants
const (
IndexingPolicyModeConsistent IndexingPolicyMode = "Consistent"
IndexingPolicyModeLazy IndexingPolicyMode = "Lazy"
)
// IncludedPath represents an included path
type IncludedPath struct {
Path string `json:"path,omitempty"`
Indexes []Index `json:"indexes,omitempty"`
}
// Index represents an index
type Index struct {
DataType IndexDataType `json:"dataType,omitempty"`
Kind IndexKind `json:"kind,omitempty"`
Precision int `json:"precision,omitempty"`
}
// IndexDataType represents an index data type
type IndexDataType string
// IndexDataType constants
const (
IndexDataTypeString IndexDataType = "String"
IndexDataTypeNumber IndexDataType = "Number"
IndexDataTypePoint IndexDataType = "Point"
IndexDataTypePolygon IndexDataType = "Polygon"
IndexDataTypeLineString IndexDataType = "LineString"
)
// IndexKind represents an index kind
type IndexKind string
// IndexKind constants
const (
IndexKindHash IndexKind = "Hash"
IndexKindRange IndexKind = "Range"
IndexKindSpatial IndexKind = "Spatial"
)
// ExcludedPath represents an excluded path
type ExcludedPath struct {
Path string `json:"path,omitempty"`
}
// PartitionKey represents a partition key
type PartitionKey struct {
Paths []string `json:"paths,omitempty"`
Kind PartitionKeyKind `json:"kind,omitempty"`
Version int `json:"version,omitempty"`
}
// PartitionKeyKind represents a partition key kind
type PartitionKeyKind string
// PartitionKeyKind constants
const (
PartitionKeyKindHash PartitionKeyKind = "Hash"
)
// ConflictResolutionPolicy represents a conflict resolution policy
type ConflictResolutionPolicy struct {
Mode ConflictResolutionPolicyMode `json:"mode,omitempty"`
ConflictResolutionPath string `json:"conflictResolutionPath,omitempty"`
ConflictResolutionProcedure string `json:"conflictResolutionProcedure,omitempty"`
}
// ConflictResolutionPolicyMode represents a conflict resolution policy mode
type ConflictResolutionPolicyMode string
// ConflictResolutionPolicyMode constants
const (
ConflictResolutionPolicyModeLastWriterWins ConflictResolutionPolicyMode = "LastWriterWins"
ConflictResolutionPolicyModeCustom ConflictResolutionPolicyMode = "Custom"
)
// GeospatialConfig represents a geospatial config
type GeospatialConfig struct {
Type GeospatialConfigType `json:"type,omitempty"`
}
// GeospatialConfigType represents geospatial config types
type GeospatialConfigType string
// GeospatialConfigType constants
const (
GeospatialConfigTypeGeography GeospatialConfigType = "Geography"
)
// Collections represents collections
type Collections struct {
Count int `json:"_count,omitempty"`
ResourceID string `json:"_rid,omitempty"`
Collections []*Collection `json:"DocumentCollections,omitempty"`
}
// PartitionKeyRanges represents partition key ranges
type PartitionKeyRanges struct {
Count int `json:"_count,omitempty"`
ResourceID string `json:"_rid,omitempty"`
PartitionKeyRanges []PartitionKeyRange `json:"PartitionKeyRanges,omitempty"`
}
// PartitionKeyRange represents a partition key range
type PartitionKeyRange struct {
ID string `json:"id,omitempty"`
ResourceID string `json:"_rid,omitempty"`
Timestamp int `json:"_ts,omitempty"`
Self string `json:"_self,omitempty"`
ETag string `json:"_etag,omitempty"`
MaxExclusive string `json:"maxExclusive,omitempty"`
MinInclusive string `json:"minInclusive,omitempty"`
ResourceIDPrefix int `json:"ridPrefix,omitempty"`
ThroughputFraction int `json:"throughputFraction,omitempty"`
Status PartitionKeyRangeStatus `json:"status,omitempty"`
Parents []string `json:"parents,omitempty"`
}
// PartitionKeyRangeStatus represents a partition key range status
type PartitionKeyRangeStatus string
// PartitionKeyRangeStatus constants
const (
PartitionKeyRangeStatusOnline PartitionKeyRangeStatus = "online"
)
type collectionClient struct {
*databaseClient
path string
}
// CollectionClient is a collection client
type CollectionClient interface {
Create(*Collection) (*Collection, error)
List() CollectionIterator
ListAll() (*Collections, error)
Get(string) (*Collection, error)
Delete(*Collection) error
Replace(*Collection) (*Collection, error)
PartitionKeyRanges(string) (*PartitionKeyRanges, error)
}
type collectionListIterator struct {
*collectionClient
continuation string
done bool
}
// CollectionIterator is a collection iterator
type CollectionIterator interface {
Next() (*Collections, error)
}
// NewCollectionClient returns a new collection client
func NewCollectionClient(c DatabaseClient, dbid string) CollectionClient {
return &collectionClient{
databaseClient: c.(*databaseClient),
path: "dbs/" + dbid,
}
}
func (c *collectionClient) all(i CollectionIterator) (*Collections, error) {
allcolls := &Collections{}
for {
colls, err := i.Next()
if err != nil {
return nil, err
}
if colls == nil {
break
}
allcolls.Count += colls.Count
allcolls.ResourceID = colls.ResourceID
allcolls.Collections = append(allcolls.Collections, colls.Collections...)
}
return allcolls, nil
}
func (c *collectionClient) Create(newcoll *Collection) (coll *Collection, err error) {
err = c.do(http.MethodPost, c.path+"/colls", "colls", c.path, http.StatusCreated, &newcoll, &coll, nil)
return
}
func (c *collectionClient) List() CollectionIterator {
return &collectionListIterator{collectionClient: c}
}
func (c *collectionClient) ListAll() (*Collections, error) {
return c.all(c.List())
}
func (c *collectionClient) Get(collid string) (coll *Collection, err error) {
err = c.do(http.MethodGet, c.path+"/colls/"+collid, "colls", c.path+"/colls/"+collid, http.StatusOK, nil, &coll, nil)
return
}
func (c *collectionClient) Delete(coll *Collection) error {
if coll.ETag == "" {
return ErrETagRequired
}
headers := http.Header{}
headers.Set("If-Match", coll.ETag)
return c.do(http.MethodDelete, c.path+"/colls/"+coll.ID, "colls", c.path+"/colls/"+coll.ID, http.StatusNoContent, nil, nil, headers)
}
func (c *collectionClient) Replace(newcoll *Collection) (coll *Collection, err error) {
err = c.do(http.MethodPost, c.path+"/colls/"+newcoll.ID, "colls", c.path+"/colls/"+newcoll.ID, http.StatusCreated, &newcoll, &coll, nil)
return
}
func (c *collectionClient) PartitionKeyRanges(collid string) (pkrs *PartitionKeyRanges, err error) {
err = c.do(http.MethodGet, c.path+"/colls/"+collid+"/pkranges", "pkranges", c.path+"/colls/"+collid, http.StatusOK, nil, &pkrs, nil)
return
}
func (i *collectionListIterator) Next() (colls *Collections, err error) {
if i.done {
return
}
headers := http.Header{}
if i.continuation != "" {
headers.Set("X-Ms-Continuation", i.continuation)
}
err = i.do(http.MethodGet, i.path+"/colls", "colls", i.path, http.StatusOK, nil, &colls, headers)
if err != nil {
return
}
i.continuation = headers.Get("X-Ms-Continuation")
i.done = i.continuation == ""
return
}