Skip to content

Commit 3304c7c

Browse files
authored
Add Collection's missing fields & remove internal structures (#377)
1 parent 3572664 commit 3304c7c

File tree

2 files changed

+48
-235
lines changed

2 files changed

+48
-235
lines changed

collection.go

Lines changed: 30 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ type CollectionInfo struct {
8787
Name string `json:"name,omitempty"`
8888
// The status of the collection
8989
Status CollectionStatus `json:"status,omitempty"`
90+
// StatusString represents status as a string.
91+
StatusString string `json:"statusString,omitempty"`
9092
// The type of the collection
9193
Type CollectionType `json:"type,omitempty"`
9294
// If true then the collection is a system collection.
@@ -98,6 +100,7 @@ type CollectionInfo struct {
98100
// CollectionProperties contains extended information about a collection.
99101
type CollectionProperties struct {
100102
CollectionInfo
103+
ArangoError
101104

102105
// WaitForSync; If true then creating, changing or removing documents will wait until the data has been synchronized to disk.
103106
WaitForSync bool `json:"waitForSync,omitempty"`
@@ -113,7 +116,8 @@ type CollectionProperties struct {
113116
// AllowUserKeys; if set to true, then it is allowed to supply own key values in the _key attribute of a document.
114117
// If set to false, then the key generator is solely responsible for generating keys and supplying own key values in
115118
// the _key attribute of documents is considered an error.
116-
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
119+
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
120+
LastValue int64 `json:"lastValue,omitempty"`
117121
} `json:"keyOptions,omitempty"`
118122
// NumberOfShards is the number of shards of the collection.
119123
// Only available in cluster setup.
@@ -123,7 +127,7 @@ type CollectionProperties struct {
123127
ShardKeys []string `json:"shardKeys,omitempty"`
124128
// ReplicationFactor contains how many copies of each shard are kept on different DBServers.
125129
// Only available in cluster setup.
126-
ReplicationFactor int `json:"replicationFactor,omitempty"`
130+
ReplicationFactor int `json:"-"`
127131
// Deprecated: use 'WriteConcern' instead
128132
MinReplicationFactor int `json:"minReplicationFactor,omitempty"`
129133
// WriteConcern contains how many copies must be available before a collection can be written.
@@ -149,6 +153,26 @@ type CollectionProperties struct {
149153
SyncByRevision bool `json:"syncByRevision,omitempty"`
150154
// Schema for collection validation
151155
Schema *CollectionSchemaOptions `json:"schema,omitempty"`
156+
157+
Revision string `json:"revision,omitempty"`
158+
159+
// IsDisjoint set isDisjoint flag for Graph. Required ArangoDB 3.7+
160+
IsDisjoint bool `json:"isDisjoint,omitempty"`
161+
162+
IsSmartChild bool `json:"isSmartChild,omitempty"`
163+
164+
InternalValidatorType *int `json:"internalValidatorType, omitempty"`
165+
166+
// Set to create a smart edge or vertex collection.
167+
// This requires ArangoDB Enterprise Edition.
168+
IsSmart bool `json:"isSmart,omitempty"`
169+
170+
// StatusString represents status as a string.
171+
StatusString string `json:"statusString,omitempty"`
172+
173+
TempObjectId string `json:"tempObjectId,omitempty"`
174+
175+
ObjectId string `json:"objectId,omitempty"`
152176
}
153177

154178
const (
@@ -195,6 +219,9 @@ const (
195219

196220
// CollectionStatistics contains the number of documents and additional statistical information about a collection.
197221
type CollectionStatistics struct {
222+
ArangoError
223+
CollectionProperties
224+
198225
//The number of documents currently present in the collection.
199226
Count int64 `json:"count,omitempty"`
200227
// The maximal size of a journal or datafile in bytes.
@@ -269,129 +296,9 @@ type CollectionStatistics struct {
269296

270297
// CollectionShards contains shards information about a collection.
271298
type CollectionShards struct {
272-
CollectionInfo
273-
274-
// CacheEnabled set cacheEnabled option in collection properties
275-
CacheEnabled bool `json:"cacheEnabled,omitempty"`
276-
277-
// Set to create a smart edge or vertex collection.
278-
// This requires ArangoDB Enterprise Edition.
279-
IsSmart bool `json:"isSmart,omitempty"`
280-
281-
KeyOptions struct {
282-
// Type specifies the type of the key generator. The currently available generators are traditional and autoincrement.
283-
Type KeyGeneratorType `json:"type,omitempty"`
284-
// AllowUserKeys; if set to true, then it is allowed to supply own key values in the _key attribute of a document.
285-
// If set to false, then the key generator is solely responsible for generating keys and supplying own key values in
286-
// the _key attribute of documents is considered an error.
287-
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
288-
} `json:"keyOptions,omitempty"`
289-
290-
// Deprecated: use 'WriteConcern' instead.
291-
MinReplicationFactor int `json:"minReplicationFactor,omitempty"`
292-
293-
// NumberOfShards is the number of shards of the collection.
294-
// Only available in cluster setup.
295-
NumberOfShards int `json:"numberOfShards,omitempty"`
296-
297-
// This attribute specifies the name of the sharding strategy to use for the collection.
298-
// Can not be changed after creation.
299-
ShardingStrategy ShardingStrategy `json:"shardingStrategy,omitempty"`
300-
301-
// ShardKeys contains the names of document attributes that are used to determine the target shard for documents.
302-
// Only available in cluster setup.
303-
ShardKeys []string `json:"shardKeys,omitempty"`
304-
305-
// Shards is a list of shards that belong to the collection.
306-
// Each shard contains a list of DB servers where the first one is the leader and the rest are followers.
307-
Shards map[ShardID][]ServerID `json:"shards,omitempty"`
308-
309-
// StatusString represents status as a string.
310-
StatusString string `json:"statusString,omitempty"`
311-
312-
// ReplicationFactor contains how many copies of each shard are kept on different DBServers.
313-
// Only available in cluster setup.
314-
ReplicationFactor int `json:"replicationFactor,omitempty"`
315-
316-
// WaitForSync; If true then creating, changing or removing documents will wait
317-
// until the data has been synchronized to disk.
318-
WaitForSync bool `json:"waitForSync,omitempty"`
319-
320-
// WriteConcern contains how many copies must be available before a collection can be written.
321-
// It is required that 1 <= WriteConcern <= ReplicationFactor.
322-
// Default is 1. Not available for satellite collections.
323-
// Available from 3.6 ArangoDB version.
324-
WriteConcern int `json:"writeConcern,omitempty"`
325-
}
326-
327-
type collectionShardsInternal struct {
328-
CollectionInfo
329-
330-
// CacheEnabled set cacheEnabled option in collection properties
331-
CacheEnabled bool `json:"cacheEnabled,omitempty"`
332-
333-
// Set to create a smart edge or vertex collection.
334-
// This requires ArangoDB Enterprise Edition.
335-
IsSmart bool `json:"isSmart,omitempty"`
336-
337-
KeyOptions struct {
338-
// Type specifies the type of the key generator. The currently available generators are traditional and autoincrement.
339-
Type KeyGeneratorType `json:"type,omitempty"`
340-
// AllowUserKeys; if set to true, then it is allowed to supply own key values in the _key attribute of a document.
341-
// If set to false, then the key generator is solely responsible for generating keys and supplying own key values in
342-
// the _key attribute of documents is considered an error.
343-
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
344-
} `json:"keyOptions,omitempty"`
345-
346-
// Deprecated: use 'WriteConcern' instead.
347-
MinReplicationFactor int `json:"minReplicationFactor,omitempty"`
348-
349-
// NumberOfShards is the number of shards of the collection.
350-
// Only available in cluster setup.
351-
NumberOfShards int `json:"numberOfShards,omitempty"`
352-
353-
// This attribute specifies the name of the sharding strategy to use for the collection.
354-
// Can not be changed after creation.
355-
ShardingStrategy ShardingStrategy `json:"shardingStrategy,omitempty"`
356-
357-
// ShardKeys contains the names of document attributes that are used to determine the target shard for documents.
358-
// Only available in cluster setup.
359-
ShardKeys []string `json:"shardKeys,omitempty"`
299+
CollectionProperties
360300

361301
// Shards is a list of shards that belong to the collection.
362302
// Each shard contains a list of DB servers where the first one is the leader and the rest are followers.
363303
Shards map[ShardID][]ServerID `json:"shards,omitempty"`
364-
365-
// StatusString represents status as a string.
366-
StatusString string `json:"statusString,omitempty"`
367-
368-
// ReplicationFactor contains how many copies of each shard are kept on different DBServers.
369-
// Only available in cluster setup.
370-
ReplicationFactor replicationFactor `json:"replicationFactor,omitempty"`
371-
372-
// WaitForSync; If true then creating, changing or removing documents will wait
373-
// until the data has been synchronized to disk.
374-
WaitForSync bool `json:"waitForSync,omitempty"`
375-
376-
// WriteConcern contains how many copies must be available before a collection can be written.
377-
// It is required that 1 <= WriteConcern <= ReplicationFactor.
378-
// Default is 1. Not available for satellite collections.
379-
// Available from 3.6 ArangoDB version.
380-
WriteConcern int `json:"writeConcern,omitempty"`
381-
}
382-
383-
func (p *CollectionShards) fromInternal(i collectionShardsInternal) {
384-
p.CollectionInfo = i.CollectionInfo
385-
p.CacheEnabled = i.CacheEnabled
386-
p.IsSmart = i.IsSmart
387-
p.KeyOptions = i.KeyOptions
388-
p.MinReplicationFactor = i.MinReplicationFactor
389-
p.NumberOfShards = i.NumberOfShards
390-
p.ShardingStrategy = i.ShardingStrategy
391-
p.ShardKeys = i.ShardKeys
392-
p.Shards = i.Shards
393-
p.StatusString = i.StatusString
394-
p.ReplicationFactor = int(i.ReplicationFactor)
395-
p.WaitForSync = i.WaitForSync
396-
p.WriteConcern = i.WriteConcern
397304
}

collection_impl.go

Lines changed: 18 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ func (c *collection) Revision(ctx context.Context) (string, error) {
143143
if err := resp.CheckStatus(200); err != nil {
144144
return "", WithStack(err)
145145
}
146-
var data struct {
147-
Revision string `json:"revision,omitempty"`
148-
}
146+
var data CollectionProperties
149147
if err := resp.ParseBody("", &data); err != nil {
150148
return "", WithStack(err)
151149
}
@@ -165,11 +163,18 @@ func (c *collection) Properties(ctx context.Context) (CollectionProperties, erro
165163
if err := resp.CheckStatus(200); err != nil {
166164
return CollectionProperties{}, WithStack(err)
167165
}
168-
var data collectionPropertiesInternal
166+
167+
var data struct {
168+
CollectionProperties
169+
ReplicationFactorV2 replicationFactor `json:"replicationFactor,omitempty"`
170+
}
171+
169172
if err := resp.ParseBody("", &data); err != nil {
170173
return CollectionProperties{}, WithStack(err)
171174
}
172-
return data.asExternal(), nil
175+
data.ReplicationFactor = int(data.ReplicationFactorV2)
176+
177+
return data.CollectionProperties, nil
173178
}
174179

175180
// SetProperties changes properties of the collection.
@@ -210,15 +215,17 @@ func (c *collection) Shards(ctx context.Context, details bool) (CollectionShards
210215
return CollectionShards{}, WithStack(err)
211216
}
212217

213-
shardsInternal := collectionShardsInternal{}
214-
if err := resp.ParseBody("", &shardsInternal); err != nil {
215-
return CollectionShards{}, WithStack(err)
218+
var data struct {
219+
CollectionShards
220+
ReplicationFactorV2 replicationFactor `json:"replicationFactor,omitempty"`
216221
}
217222

218-
var shards CollectionShards
219-
shards.fromInternal(shardsInternal)
223+
if err := resp.ParseBody("", &data); err != nil {
224+
return CollectionShards{}, WithStack(err)
225+
}
226+
data.ReplicationFactor = int(data.ReplicationFactorV2)
220227

221-
return shards, nil
228+
return data.CollectionShards, nil
222229
}
223230

224231
// Load the collection into memory.
@@ -296,107 +303,6 @@ func (c *collection) Truncate(ctx context.Context) error {
296303
return nil
297304
}
298305

299-
type collectionPropertiesInternal struct {
300-
CollectionInfo
301-
WaitForSync bool `json:"waitForSync,omitempty"`
302-
DoCompact bool `json:"doCompact,omitempty"`
303-
JournalSize int64 `json:"journalSize,omitempty"`
304-
CacheEnabled bool `json:"cacheEnabled,omitempty"`
305-
KeyOptions struct {
306-
Type KeyGeneratorType `json:"type,omitempty"`
307-
AllowUserKeys bool `json:"allowUserKeys,omitempty"`
308-
} `json:"keyOptions,omitempty"`
309-
NumberOfShards int `json:"numberOfShards,omitempty"`
310-
ShardKeys []string `json:"shardKeys,omitempty"`
311-
ReplicationFactor replicationFactor `json:"replicationFactor,omitempty"`
312-
// Deprecated: use 'WriteConcern' instead
313-
MinReplicationFactor int `json:"minReplicationFactor,omitempty"`
314-
// Available from 3.6 arangod version.
315-
WriteConcern int `json:"writeConcern,omitempty"`
316-
SmartJoinAttribute string `json:"smartJoinAttribute,omitempty"`
317-
ShardingStrategy ShardingStrategy `json:"shardingStrategy,omitempty"`
318-
DistributeShardsLike string `json:"distributeShardsLike,omitempty"`
319-
// Available from 3.7 arangod version.
320-
UsesRevisionsAsDocumentIds bool `json:"usesRevisionsAsDocumentIds,omitempty"`
321-
SyncByRevision bool `json:"syncByRevision,omitempty"`
322-
Schema *CollectionSchemaOptions `json:"schema,omitempty"`
323-
}
324-
325-
func (p *collectionPropertiesInternal) asExternal() CollectionProperties {
326-
return CollectionProperties{
327-
CollectionInfo: p.CollectionInfo,
328-
WaitForSync: p.WaitForSync,
329-
DoCompact: p.DoCompact,
330-
JournalSize: p.JournalSize,
331-
CacheEnabled: p.CacheEnabled,
332-
KeyOptions: p.KeyOptions,
333-
NumberOfShards: p.NumberOfShards,
334-
ShardKeys: p.ShardKeys,
335-
ReplicationFactor: int(p.ReplicationFactor),
336-
MinReplicationFactor: p.MinReplicationFactor,
337-
WriteConcern: p.WriteConcern,
338-
SmartJoinAttribute: p.SmartJoinAttribute,
339-
ShardingStrategy: p.ShardingStrategy,
340-
DistributeShardsLike: p.DistributeShardsLike,
341-
UsesRevisionsAsDocumentIds: p.UsesRevisionsAsDocumentIds,
342-
SyncByRevision: p.SyncByRevision,
343-
Schema: p.Schema,
344-
}
345-
}
346-
347-
func (p *CollectionProperties) asInternal() collectionPropertiesInternal {
348-
return collectionPropertiesInternal{
349-
CollectionInfo: p.CollectionInfo,
350-
WaitForSync: p.WaitForSync,
351-
DoCompact: p.DoCompact,
352-
JournalSize: p.JournalSize,
353-
CacheEnabled: p.CacheEnabled,
354-
KeyOptions: p.KeyOptions,
355-
NumberOfShards: p.NumberOfShards,
356-
ShardKeys: p.ShardKeys,
357-
ReplicationFactor: replicationFactor(p.ReplicationFactor),
358-
MinReplicationFactor: p.MinReplicationFactor,
359-
WriteConcern: p.WriteConcern,
360-
SmartJoinAttribute: p.SmartJoinAttribute,
361-
ShardingStrategy: p.ShardingStrategy,
362-
Schema: p.Schema,
363-
}
364-
}
365-
366-
func (p *CollectionProperties) fromInternal(i *collectionPropertiesInternal) {
367-
p.CollectionInfo = i.CollectionInfo
368-
p.WaitForSync = i.WaitForSync
369-
p.DoCompact = i.DoCompact
370-
p.JournalSize = i.JournalSize
371-
p.CacheEnabled = i.CacheEnabled
372-
p.KeyOptions = i.KeyOptions
373-
p.NumberOfShards = i.NumberOfShards
374-
p.ShardKeys = i.ShardKeys
375-
p.ReplicationFactor = int(i.ReplicationFactor)
376-
p.MinReplicationFactor = i.MinReplicationFactor
377-
p.WriteConcern = i.WriteConcern
378-
p.SmartJoinAttribute = i.SmartJoinAttribute
379-
p.ShardingStrategy = i.ShardingStrategy
380-
p.UsesRevisionsAsDocumentIds = i.UsesRevisionsAsDocumentIds
381-
p.SyncByRevision = i.SyncByRevision
382-
}
383-
384-
// MarshalJSON converts CollectionProperties into json
385-
func (p *CollectionProperties) MarshalJSON() ([]byte, error) {
386-
return json.Marshal(p.asInternal())
387-
}
388-
389-
// UnmarshalJSON loads CollectionProperties from json
390-
func (p *CollectionProperties) UnmarshalJSON(d []byte) error {
391-
var internal collectionPropertiesInternal
392-
if err := json.Unmarshal(d, &internal); err != nil {
393-
return err
394-
}
395-
396-
p.fromInternal(&internal)
397-
return nil
398-
}
399-
400306
type setCollectionPropertiesOptionsInternal struct {
401307
WaitForSync *bool `json:"waitForSync,omitempty"`
402308
JournalSize int64 `json:"journalSize,omitempty"`

0 commit comments

Comments
 (0)