-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_util_create.go
56 lines (51 loc) · 2.15 KB
/
client_util_create.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
package goC8
import (
"errors"
"github.com/marvin-hansen/goC8/requests/index_req"
"github.com/marvin-hansen/goC8/types"
)
func CreateCollection(c *Client, fabric, collectionName string, collectionType types.CollectionType, allowUserKeys bool) {
exists, err := c.Collection.CheckCollectionExists(fabric, collectionName)
CheckError(err, "Error CheckCollectionExists: ")
if !exists {
// if not, create
err = c.Collection.CreateNewCollection(fabric, collectionName, allowUserKeys, collectionType)
CheckError(err, "Error CreateNewCollection")
}
}
func ImportCollectionData(c *Client, fabric, collectionName string, jsonDocument []byte, silent bool) {
exists, err := c.Collection.CheckCollectionExists(fabric, collectionName)
CheckError(err, "Error CheckCollectionExists: ")
if exists {
// if not, create
_, err = c.Document.CreateNewDocument(fabric, collectionName, silent, jsonDocument, nil)
CheckError(err, "Error CreateNewDocument")
}
}
func CreateGraph(c *Client, fabric, graphName string, jsonGraph []byte) {
exists, err := c.Graph.CheckGraphExists(fabric, graphName)
CheckError(err, "Error CheckGraphExists: ")
if !exists {
// if not, create
_, createGraphErr := c.Graph.CreateGraph(fabric, jsonGraph)
CheckError(createGraphErr, "Error CreateGraph")
}
}
func CreateIndex(c *Client, fabric, collectionName, field string, indexType types.IndexType, deduplicate, sparse, unique, geoJson bool) (response *index_req.IndexEntry, err error) {
switch indexType {
case types.FulltextIndex:
return c.Index.CreateFulltextIndex(fabric, collectionName, field, 3)
case types.HashIndex:
return c.Index.CreateHashIndex(fabric, collectionName, field, deduplicate, sparse, unique)
case types.GeoIndex:
return c.Index.CreateGeoIndex(fabric, collectionName, field, geoJson)
case types.PersistentIndex:
return c.Index.CreatePersistentIndex(fabric, collectionName, field, deduplicate, sparse, unique)
case types.SkipListIndex:
return c.Index.CreateSkipListIndex(fabric, collectionName, field, deduplicate, sparse, unique)
case types.TTLIndex:
return c.Index.CreateTTLIndex(fabric, collectionName, field, 5)
default:
return nil, errors.New("unknown index type")
}
}