goC8

package module
v1.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2022 License: MIT Imports: 19 Imported by: 0

README

goC8

Welcome to the GitHub page for goC8, a Golang client for the macrometa global data platform (GDN).

About

Macrometa is a secure, global data platform with integrated pub/sub, stream processing, search, functions, and 4 databases all through one single API. GDN clients for Python, Java, and Javascript are available from Macrometa. goC8 is an open source client that implements the Macrometa API for Golang.

Use cases

  • Legal compliance with data residency regulations & EU GDPR regulations
  • Global data to cluster co-location for low latency data access
  • Web Assembly (WASM) storage
  • Unified single storage API
  • Microservice storage
  • Kubernetes storage
  • Mobile app storage
  • Single, globally distributed & fail-safe, storage backend shared between web, mobile, & cluster applications
  • Event storage & streaming for real-time data analytics wth real-time client updates

Install

go get github.com/marvin-hansen/goC8/client

Authentication

Currently, only API key authentication is supported.

Configuration

If you have not worked with macrometa's plattform before, you have to do a one-time setup. See this guide for details about creating a data fabric for your project.

The client config requires the following settings:

  • Api Key
  • Endpoint
  • Fabric
  • Timeout

Api Key refers to the generated api access key. Endpoint refers to the POP provided by the GDN. Fabric refers to the GDN Geo Fabric. Timeout refers to the http connection timeout in seconds. If you do not have these value at hand, please read the setup guide for details.

API

Data API
Query API

Consult the status document for details about which API implementation. Note, the bulk of the data & query API has been completed, but the admin API has not been implemented. Feel free to contribute a PR to close some gaps.

Code Examples

Golang demo apps from Macrometa

Usage: Graph, collection, & document API

Full code in Flight example

package main

import (
	"log"
	"github.com/marvin-hansen/goC8"
	"github.com/marvin-hansen/goC8/examples/sample_data"
	"github.com/marvin-hansen/goC8/tests/utils"
)

const (
	// client config
	apiKey   = "email.root.secretkey.xxxxxxxxxxxxxxxxx"
	endpoint = "https://YOUR-ID-us-west.paas.macrometa.io"
	fabric   = "MyFabric"
	timeout  = 5 // http connection timeout in seconds 
	// collection, document & graph config
	delete           = false
	verbose          = true
	graph            = "airline"
	collectionID     = "cities"
	edgeCollectionID = "flights"
)

func main() {
	println("Create new config ")
	config := goC8.NewConfig(apiKey, endpoint, fabric, timeout)

	println("Create new client with config ")
	c := goC8.NewClient(config)
	
	println("Setup: Create Graph, collections & import data")
	setup(c)

	println("Query: Document & Graph")
	query(c)

	if delete {
		println("Teardown: Delete Graph & Data")
		teardown(c)
	}
}

func query(c *goC8.Client) {
	var q = ""
	var msg = ""

	q = sample_data.GetAllCitiesQuery()
	msg = "Get all cities."
	runQuery(c, q, msg)

	q = sample_data.GetBreadthFirstQuery()
	msg = "Get all cities with a direct flight to New York."
	runQuery(c, q, msg)

	q = sample_data.GetShortestPathQuery()
	msg = "Get the shortest path from San Francisco to Paris."
	runQuery(c, q, msg)

	q = sample_data.GetShortestDistanceQuery()
	msg = "Get the distance on the shortest path from San Francisco to Paris."
	runQuery(c, q, msg)

	q = sample_data.GetNearestCities()
	msg = "Get the 2 nearest cities to a specified latitude and longitude."
	runQuery(c, q, msg)

	q = sample_data.GetCitiesMaxDistance()
	msg = "Get the cities that are no more than 2500km away from houston."
	runQuery(c, q, msg)
}

func runQuery(c *goC8.Client, q, msg string) {
	println(msg)
	res, err := c.Query(fabric, q, nil, nil)
	goC8.CheckError(err, "Error Query: "+q)
	goC8.PrintQuery(res, verbose)
}

// setup & teardown use the built-in utilities to create collection, index, graph & import data.
func setup(c *goC8.Client) {
	goC8.CreateCollection(c, fabric, collectionID, types.DocumentCollectionType, false)
	field := "location" // We have to create a geo index with geoJson enabled on field location before importing data
	goC8.CreateIndex(c, fabric, collectionID, field, types.GeoIndex, true, true, true, true)
	goC8.ImportCollectionData(c, fabric, collectionID, sample_data.GetCityData(), silent)
	goC8.CreateCollection(c, fabric, edgeCollectionID, types.EdgeCollectionType, false)
	goC8.ImportCollectionData(c, fabric, edgeCollectionID, sample_data.GetFlightData(), silent)
	goC8.CreateGraph(c, fabric, graph, sample_data.GetAirlineGraph())
}

func teardown(c *goC8.Client) {
	goC8.TeardownGraph(c, fabric, graph, true)
	goC8.TeardownCollection(c, fabric, collectionID)
	goC8.TeardownCollection(c, fabric, edgeCollectionID)
}

Usage: Updating graph structure & data

Suppose you have a university graph in which teachers hold multiple lectures and some lectures are given by two or more teachers. In total, the graph consists of three collections:

  1. Lectures
  2. Teachers
  3. "teach" edge that connects teachers to lectures

After all collections have been created and sample data have been imported, the graph console shows the following result:

University graph.

We see that Jean seems to be busy teaching multiple classes, while Jams & Han co-teach one of the advanced courses. After the initial success, the Dean's office asks you "to do the same for tutorials".

In this university, some tutorials are given by junior teachers who also co-teach lectures. That means, we need two new types, one vertex type for tutorials, and a second edge type that connects teachers to tutorials. That way, a teacher may give one or more lectures, but also may give one or more tutorials.

To add the tutorials to the university graph two new collections, tutorials & tutors. To do so, we take a look at the test case from the graph API test suite.

Essentially, the test does three steps to update the graph:

  1. Test if a collection exists
    • If not, create a new collection
    • If so, test if the collection already is in the graph
  2. Import or add data if available
  3. Add the (new) collection to the graph
func TestAddEdgeCollection(t *testing.T) {
	c := goC8.NewClient(config.GetDefaultConfig())

	// check if collection already exists
	exists, err := c.Collection.CheckCollectionExists(fabric, collectionTutorials)
	goC8.CheckError(err, "Error CheckCollectionExists: ")
	if !exists {
		// 1. if not create collection
		collType := types.DocumentCollectionType
		allowUserKeys := false
		err = c.Collection.CreateNewCollection(fabric, collectionTutorials, allowUserKeys, collType)
		assert.NoError(t, err)

		// 2. import data
		jsonDocument := sample_data.GetTutorialsData()
		_, err = c.Document.CreateNewDocument(fabric, collectionTutorials, silent, jsonDocument, nil)
		assert.NoError(t, err)

		// 3. Add vertex collection to graph
		_, err = c.Graph.AddVertexCollection(fabric, graphName, collectionTutorials)
		assert.NoError(t, err)
	}

	// check if collection already exists
	exists, err = c.Collection.CheckCollectionExists(fabric, edgeCollectionTutors)
	goC8.CheckError(err, "Error CheckCollectionExists")
	if !exists {
		// 1. if not create edge collection
		collType := types.EdgeCollectionType
		err = c.Collection.CreateNewCollection(fabric, edgeCollectionTutors, false, collType)
		assert.NoError(t, err)

		// 2. import data
		jsonDocument := sample_data.GetTutorsEdgeData()
		_, err = c.Document.CreateNewDocument(fabric, edgeCollectionTutors, silent, jsonDocument, nil)
		assert.NoError(t, err)

		// 3. add edge collection to graph
		collectionName := edgeCollectionTutors
		sourceVertex := "teachers"
		destinationVertex := "tutorials"

		res, createErr := c.Graph.AddEdgeCollection(fabric, graphName, collectionName, sourceVertex, destinationVertex)
		assert.NoError(t, createErr)
		assert.NotNil(t, res)
		goC8.PrintRes(res, verbose)
	}
}

After the tutorial system was implemented, it became obvious that Han already handles five tutorials in addition to teaching CS105. The dean's office decided to add Bruce as a third co-teacher to CS105 to ensure quality of teaching does not suffer. To add the new edge, from teacher Bruce to lecture CS105, you check if the edge already exsits and just call the API method CreateEdge() as shown below.

There are two ways to call CreateEdge()

  1. With a custom Json payload, as shown in the example
  2. By providing from / to, which in the example are left as empty strings. When using this, jsonPayload must be nil.

The difference is as following:

  1. Using a custom payload allows for custom attributes i.e. "online" and custom primary keys set in the _key field.
  2. Just setting from/to fields means no custom attributes are possible and primary keys will be generated by the system.

The first scenario allows rich edges but requires custom primary key management. As shown in the example, just generating the key from the primary keys of the from/to collection should be sufficient to sustain unique primary keys. The second scenario helps with bulk inserts of basic relations in which the key isn't of interest.

func TestAddEdge(t *testing.T) {
   c := goC8.NewClient(config.GetDefaultConfig())
   collectionID := "teach"
   edgeID := "Bruce-CSC105"
   returnNew := false
   
   // check if edge already exits
   exists, err := c.Graph.CheckEdgeExists(fabric, graphName, collectionID, edgeID)
   goC8.CheckError(err, "Error CheckEdgeExists")
   if !exists {
   // if not, add a new edge to the edge collection
   jsonPayload := []byte(`{
               "_key": "Bruce-CSC105",
               "_from": "teachers/Bruce",
               "_to": "lectures/CSC105",
               "online": false
           }`)
   _, createErr := c.Graph.CreateEdge(fabric, graphName, collectionID, "", "", jsonPayload, returnNew)
   assert.NoError(t, createErr)
   }
}

Take a look at the graph console to see how nicely teachers are linked to lectures and tutorials.

University graph.

With the university graph in place, it is relatively simple to add basic resource planning i.e. linking courses to lecture halls and tutorial to seminar rooms or add some queries similar to the one in the flight example.

It is worth mentioning that edges may contain arbitrary attributes so you can add additional information to filter edges during query time. In the university examples, each "teach" edge contains a boolean flag indicating if that lecture is held online. Additional information can be added i.e. the term the lecture is usually scheduled or the maximum number of allowed students to support capacity planning during enrollment. During query time, one can filter these attributes i.e. find all lectures on campus (online=false) with enrollment at 90% or more of capacity.
Or, in an attempt to validate the last annual staff review: Find all teachers with the lowest enrollment grouped by class difficulty and seek a conversation with whoever comes up.

Make reference

Setup: 
    make check                  Checks all requirements.
 
Test: 
    make test-all               Runs all API tests.
    make test-collection        Tests collection API. 
    make test-document          Tests document API. 
    make test-index             Tests index API. 
    make test-kv                Tests key-value API. 
    make test-query             Tests query API. 
    make test-query-worker      Tests query worker API. 

Known issues and solutions

Illegal key while creating ....

This error means that the provided key, name, or identifier in question does not adhere to the established convention. Names for collections, documents, graphs, and edges follow the same convention as keys, there is a high chance that the identifier contains a blank or non-allowed character triggering this error. When writing insert functions with custom primary keys, it is paramount to stick to the naming convention to prevent runtime errors.

For details, please look at the

Notice, the problem in the Stack Overflow question was the blank in the graph name. A fix would be eliminating the blank by renaming the graph from "Friends visit" to "FriendsVisit" to adhere to the naming convention.

VPackError error: Expecting digit

Error number 400 / 600

This error means that the provided JSON doesn't conform to the standard.

Use a JSON validator and check for common issues:

  • Missing comma between array values
  • Comma after last attribute
  • Singe quote ' instead of double " quote

Notice, the JSON unpacker is rather fragile so whatever "small fixes" the validator suggests, apply them otherwise the error persists.

Author

  • Marvin Hansen
  • GPG key ID: 210D39BC
  • Github key ID: 369D5A0B210D39BC
  • GPG Fingerprint: 4B18 F7B2 04B9 7A72 967E 663E 369D 5A0B 210D 39BC
  • Public key: key

Licence

  • MIT Licence
  • Software is "as is" without any warranty.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckError added in v1.3.1

func CheckError(err error, msg string)

func CheckErrorLog added in v1.3.1

func CheckErrorLog(err error, msg string)

func CheckReturnError added in v1.4.1

func CheckReturnError(err error) error

func CreateCollection added in v1.4.1

func CreateCollection(c *Client, fabric, collectionName string, collectionType types.CollectionType, allowUserKeys bool)

func CreateGraph added in v1.4.1

func CreateGraph(c *Client, fabric, graphName string, jsonGraph []byte)

func CreateIndex added in v1.4.1

func CreateIndex(c *Client, fabric, collectionName, field string, indexType types.IndexType, deduplicate, sparse, unique, geoJson bool) (response *index_req.IndexEntry, err error)

func ImportCollectionData added in v1.4.1

func ImportCollectionData(c *Client, fabric, collectionName string, jsonDocument []byte, silent bool)

func PrintJsonRes added in v0.0.8

func PrintJsonRes(res types.JsonResponder, verbose bool)

func PrintQuery added in v0.0.8

func PrintQuery(res *query_req.Cursor, verbose bool)

func PrintRes added in v0.0.8

func PrintRes(res types.Responder, verbose bool)

func TeardownCollection added in v1.4.1

func TeardownCollection(c *Client, fabric, collectionName string)

func TeardownGraph added in v1.4.1

func TeardownGraph(c *Client, fabric, graphName string, dropCollections bool)

Types

type APIError

type APIError struct {
	Code         int    `json:"code"`
	IsError      bool   `json:"error"`
	ErrorMessage string `json:"errorMessage"`
	ErrorNum     int    `json:"errorNum"`
}

APIError return the api error

func (APIError) Error

func (e APIError) Error() string

Error return the error message

type Client

type Client struct {
	Endpoint    string
	HTTPC       *fasthttp.Client
	HTTPTimeout time.Duration
	Collection  *CollectionManager
	Document    *DocumentManager
	Graph       *GraphManager
	Index       *IndexManager
	KV          *KVManager
	Query       *QueryManager
	QueryWorker *QueryWorkerManager
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config *ClientConfig) *Client

func (Client) Info added in v0.0.3

func (c Client) Info()

func (*Client) Request added in v1.4.1

func (c *Client) Request(req types.Requester, results types.Responder) error

func (Client) Version added in v0.0.4

func (c Client) Version() string

type ClientConfig

type ClientConfig struct {
	Fabric   string
	Timeout  int
	QueryTTL int
	// contains filtered or unexported fields
}

func NewConfig added in v0.0.3

func NewConfig(apiKey, endpoint, fabric string, timeout int) *ClientConfig

func (ClientConfig) GetApiKey added in v0.0.3

func (c ClientConfig) GetApiKey() string

func (ClientConfig) GetConnectionString

func (c ClientConfig) GetConnectionString() string

func (ClientConfig) GetQueryTTL added in v0.0.4

func (c ClientConfig) GetQueryTTL() int

type CollectionManager added in v1.4.1

type CollectionManager struct {
	// contains filtered or unexported fields
}

func NewCollectionManager added in v1.4.1

func NewCollectionManager(client *Client) *CollectionManager

func (CollectionManager) CheckCollectionExists added in v1.4.1

func (c CollectionManager) CheckCollectionExists(fabric, collectionName string) (exists bool, err error)

CheckCollectionExists Returns true if the collection of the name exists. False otherwise.

func (CollectionManager) CountCollection added in v1.4.1

func (c CollectionManager) CountCollection(fabric, collectionName string) (response *collection_req.ResultFromCollection, err error)

CountCollection Returns the number of documents in the collection. Note: This always loads the collection into memory.

The call returns a JSON object with at least the following attributes on success: error: false count: The number of documents inside the collection. id: The id of collection as string. name: The name of collection as string. isSystem: True if the collection is a system collection. searchEnabled: True if the collection is searchable. globallyUniqueId: Global unique identifier as string. https://macrometa.com/docs/api#/operations/handleCommandGet:getCollectionCount

func (CollectionManager) CreateNewCollection added in v1.4.1

func (c CollectionManager) CreateNewCollection(fabric, collectionName string, allowUserKeys bool, collectionType types.CollectionType) (err error)

CreateNewCollection Creates a new collection with a given name. The request must contain an object with the following attributes. name: The name of the collection. keyOptions: allowUserKeys: If set to true, you can supply a key value in the _key attribute of a document. If set to false, the key generator creates keys, and an error occurs if you add a _key value. type: Choose the type of key generator: traditional: generates numerical keys in ascending order. autoincrement: generates numerical keys in ascending order with configurable initial offset and spacing. padded: generates keys of a fixed length (16 bytes) in ascending lexicographical sort order. uuid64: generates universally unique keys. increment: increment value for autoincrement key generator. Not used for other key generator types. offset: Initial offset value for autoincrement key generator. Not used for other key generator types. isSystem: If true, create a system collection. The collection-name must start with an underscore. Not Applicable for end-users. (The default is false) isLocal: If true, create a local collection. For a local collection data is not replicated across regions. (The default is false) type: The type of the collection to be created. The following values for type are valid (The default is 2): 2: document collection 3: edge collection. stream: If true, create a local stream for collection. (The default is false) shardKeys: The specified shard key determines in which shard a given document is to be stored. Choosing the right shard key can have significant impact on your performance can reduce network traffic and increase performance. https://macrometa.com/docs/api#/operations/handleCommandPost:CreateCollection

func (CollectionManager) DeleteCollection added in v1.4.1

func (c CollectionManager) DeleteCollection(fabric, collectionName string, isSystem bool) (err error)

DeleteCollection Drops the collection identified by collection-name. If the collection was successfully dropped, an object is returned with the following attributes: error: false id: The identifier of the dropped collection. https://macrometa.com/docs/api#/operations/handleCommandDelete:collection

func (CollectionManager) GetAllCollections added in v1.4.1

func (c CollectionManager) GetAllCollections(fabric string) (response *collection_req.ResponseForGetAllCollections, err error)

GetAllCollections Returns an object with an attribute collections containing an array of all collection descriptions. The same information is also available in the names as an object with the collection names as keys. By providing the optional query parameter excludeSystem with a value of true, all system collections will be excluded from the response. https://macrometa.com/docs/api#/operations/handleCommandGet

func (CollectionManager) GetCollectionInfo added in v1.4.1

func (c CollectionManager) GetCollectionInfo(fabric, collectionName string) (response *collection_req.ResponseForGetCollectionInfo, err error)

GetCollectionInfo Fetches the information about collection. https://macrometa.com/docs/api#/operations/handleCommandGet:collectionGetProperties

func (CollectionManager) TruncateCollection added in v1.4.1

func (c CollectionManager) TruncateCollection(fabric, collectionName string) (response *collection_req.ResponseForTruncateCollection, err error)

TruncateCollection Remove all documents from the collection but leaves the indexes intact. https://macrometa.com/docs/api#/operations/handleCommandPut:truncateCollection

func (CollectionManager) UpdateCollectionProperties added in v1.4.1

func (c CollectionManager) UpdateCollectionProperties(fabric, collectionName string, properties *collection_req.UpdateOptions) (response *collection_req.ResponseForUpdateCollection, err error)

UpdateCollectionProperties updates collection properties. Note: except for waitForSync and hasStream, collection properties cannot be changed once a collection is created. Changes the properties of a collection. Requires a JSON object with these properties:

hasStream: True if creating a live collection stream. waitForSync: True if waiting for documents to be synchronized to storage. The call returns a JSON object with at least the following attributes on success: id: The identifier of the collection. name: The name of the collection. status: The status of the collection as number. 1: new born collection 2: unloaded 3: loaded 4: in the process of being unloaded 5: deleted 6: loading Every other status indicates a corrupted collection. type: The type of the collection as number. 2: document collection (normal case) 3: edges collection isSystem: True then the collection is a system collection. stream: True if the collection has a local streams associate with it. Note: except for waitForSync and hasStream, collection properties cannot be changed once a collection is created. https://macrometa.com/docs/api#/operations/handleCommandPut:stream

type DocumentManager added in v1.4.1

type DocumentManager struct {
	// contains filtered or unexported fields
}

func NewDocumentManager added in v1.4.1

func NewDocumentManager(client *Client) *DocumentManager

func (DocumentManager) CheckDocumentExists added in v1.4.1

func (c DocumentManager) CheckDocumentExists(
	fabric string, collectionName string, key string) (exists bool, err error)

func (DocumentManager) CreateNewDocument added in v1.4.1

func (c DocumentManager) CreateNewDocument(
	fabric string, collectionName string, silent bool, jsonDocument []byte,
	parameters *document_req.CreateDocumentParameters) (response *document_req.ResponseForCreateDocument, err error)

CreateNewDocument silent - If set to false, the primary key of the new doc is returned. If set to true, an empty object is returned as response. No meta-data is returned for the created document. This option can be used to save some network traffic. True by default parameters - additional query parameters for non-standard cases. jsonDocument the document to store in the collection

func (DocumentManager) DeleteDocument added in v1.4.1

func (c DocumentManager) DeleteDocument(
	fabric string, collectionName string, key string,
	parameters *document_req.DeleteDocumentParameters) (response *document_req.ResponseForDeleteDocument, err error)

func (DocumentManager) DeleteManyDocuments added in v1.4.1

func (c DocumentManager) DeleteManyDocuments(
	fabric string, collectionName string, keysToDelete []byte,
	parameters *document_req.DeleteDocumentParameters) (response *document_req.ResponseForDeleteManyDocuments, err error)

func (DocumentManager) GetDocument added in v1.4.1

func (c DocumentManager) GetDocument(
	fabric string, collectionName string, key string) (response *document_req.ResponseForGetJsonDocument, err error)

func (DocumentManager) ReplaceDocument added in v1.4.1

func (c DocumentManager) ReplaceDocument(
	fabric string, collectionName, key string, jsonDocuments []byte,
	parameters *document_req.ReplaceDocumentParameters) (response *document_req.ResponseForReplaceDocument, err error)

func (DocumentManager) ReplaceManyDocuments added in v1.4.1

func (c DocumentManager) ReplaceManyDocuments(
	fabric string, collectionName string, jsonDocuments []byte,
	parameters *document_req.ReplaceDocumentParameters) (response *document_req.ResponseForReplaceManyDocument, err error)

func (DocumentManager) UpdateDocument added in v1.4.1

func (c DocumentManager) UpdateDocument(
	fabric string, collectionName string, key string,
	jsonDocument []byte,
	silent bool,
	parameters *document_req.UpdateDocumentParameters,
) (response *document_req.ResponseForUpdateDocument, err error)

func (DocumentManager) UpdateManyDocuments added in v1.4.1

func (c DocumentManager) UpdateManyDocuments(
	fabric string, collectionName string, jsonDocument []byte,
	parameters *document_req.UpdateDocumentParameters) (response *document_req.ResponseForUpdateManyDocument, err error)

type GraphManager added in v1.4.1

type GraphManager struct {
	// contains filtered or unexported fields
}

func NewGraphManager added in v1.4.1

func NewGraphManager(client *Client) *GraphManager

func (GraphManager) AddEdgeCollection added in v1.4.1

func (c GraphManager) AddEdgeCollection(fabric, graphName, edgeCollectionName, sourceVertex, destinationVertex string) (response *edge_req.ResponseForAddEdgeCollection, err error)

AddEdgeCollection Adds an additional edge definition to the graph. This edge definition has to contain a collection and an array of each from and to vertex collections. An edge definition can only be added if this definition is either not used in any other graph, or it is used with exactly the same definition. * edgeCollectionName: The name of the edge collection to be used. * sourceVertex (string): One or many vertex collections that can contain source vertices. * destinationVertex (string): One or many vertex collections that can contain target vertices. https://macrometa.com/docs/api#/operations/AddEdgedefinition

func (GraphManager) AddVertexCollection added in v1.4.1

func (c GraphManager) AddVertexCollection(fabric, graphName, vertexCollectionName string) (response *graph_req.ResponseForGraph, err error)

AddVertexCollection Adds a vertex collection to the set of orphan collections of the graph. If the collection does not exist, it will be created.

func (GraphManager) CheckEdgeCollectionExists added in v1.4.1

func (c GraphManager) CheckEdgeCollectionExists(fabric, collectionName string) (exists bool, err error)

CheckEdgeCollectionExists Returns true if the collection of the name exists. False otherwise.

func (GraphManager) CheckEdgeExists added in v1.4.1

func (c GraphManager) CheckEdgeExists(fabric, graphName, collectionName, edgeKey string) (exists bool, err error)

CheckEdgeExists returns true if the edge exists in the given collection

func (GraphManager) CheckGraphExists added in v1.4.1

func (c GraphManager) CheckGraphExists(fabric, graphName string) (exists bool, err error)

CheckGraphExists returns true if a graph for the given name exists

func (GraphManager) CreateEdge added in v1.4.1

func (c GraphManager) CreateEdge(fabric, graphName, edgeCollectionName, sourceVertex, destinationVertex string, jsonPayload []byte, returnNew bool) (response *edge_req.ResponseForCreateEdge, err error)

CreateEdge Creates a new edge in the collection There are two ways to call CreateEdge() A) Custom edge With a custom Json payload, as shown in the example By providing from / to, which in the example are left as empty strings. When using this, jsonPayload must be nil. Using a custom payload allows for custom attributes i.e. "online" and custom primary keys set in the _key field. B) Default edge Just setting from/to fields means no custom attributes are possible and primary keys will be generated by the system. The second scenario helps with bulk inserts of basic relations in which the key isn't of interest. sourceVertex: The source vertex of this edge. Has to be valid within the used edge definition. destinationVertex: The target vertex of this edge. Has to be valid within the used edge definition.

func (GraphManager) CreateGraph added in v1.4.1

func (c GraphManager) CreateGraph(fabric string, jsonGraph []byte) (response *graph_req.ResponseForCreateGraph, err error)

CreateGraph The creation of a graph requires the name of the graph and a definition of its edges. Note: Requires Administrator permissions to access the GeoFabric and Read Only access on every collection used within this graph. Sample edge definition:

{
 "edgeDefinitions": [
   {
     "collection": "edgeName",
     "from": [
       "sourceNode"
     ],
     "to": [
       "destinationNode"
     ]
   }
 ],
 "name": "exampleGraph",
 "options": {}
}

https://macrometa.com/docs/api#/operations/CreateAGraph

func (GraphManager) CreateVertex added in v1.4.1

func (c GraphManager) CreateVertex(fabric, graphName, collectionName string, jsonDef []byte, returnNew bool) (response *graph_req.ResponseForVertex, err error)

CreateVertex Adds a vertex to the given collection. returnNew - boolean Define if the response should contain the complete new version of the document.Show all... https://macrometa.com/docs/api#/operations/CreateAVertex

func (GraphManager) DeleteEdge added in v1.4.1

func (c GraphManager) DeleteEdge(fabric, graphName, collectionName, edgeKey string, returnOld bool) (response *graph_req.ResponseForEdge, err error)

DeleteEdge Removes an edge from the collection. https://macrometa.com/docs/api#/operations/RemoveAnEdge

func (GraphManager) DeleteEdgeCollection added in v1.4.1

func (c GraphManager) DeleteEdgeCollection(fabric, graphName, collectionName string, dropCollections bool) (response *graph_req.ResponseForGraph, err error)

DeleteEdgeCollection Remove one edge definition from the graph. This only removes the edge collection, the vertex collections remain untouched and can still be used in your queries. https://macrometa.com/docs/api#/operations/RemoveAnEdgedefinitionFromTheGraph

func (GraphManager) DeleteGraph added in v1.4.1

func (c GraphManager) DeleteGraph(fabric, graphName string, dropCollections bool) (response *graph_req.ResponseForDeleteGraph, err error)

DeleteGraph Remove an existing graph object by name. Optionally all collections not used by other graphs can be removed as well. https://macrometa.com/docs/api#/operations/DropAGraph

func (GraphManager) DeleteVertex added in v1.4.1

func (c GraphManager) DeleteVertex(fabric, graphName, collectionName, vertexKey string, returnOld bool) (response *graph_req.ResponseForVertex, err error)

DeleteVertex Removes a vertex from the collection. returnOld boolean - Define if a presentation of the deleted document should be returned https://macrometa.com/docs/api#/operations/RemoveAVertex

func (GraphManager) DeleteVertexCollection added in v1.4.1

func (c GraphManager) DeleteVertexCollection(fabric, graphName, collectionName string, dropCollections bool) (response *graph_req.ResponseForGraph, err error)

DeleteVertexCollection Removes a vertex collection from the graph and optionally removes the collection, if it is not used in any other graph. It only removes vertex collections that are no longer part of edge definitions. dropCollection - Remove the collection as well. Collection is only removed if it is not used in other graphs. https://macrometa.com/docs/api#/operations/RemoveVertexCollection

func (GraphManager) GetAllEdges added in v1.4.1

func (c GraphManager) GetAllEdges(fabric, graphName string) (response *edge_req.ResponseForGetAllEdges, err error)

GetAllEdges Lists all edge collections within this graph. https://macrometa.com/docs/api#/operations/ListEdgedefinitions

func (GraphManager) GetAllGraphs added in v1.4.1

func (c GraphManager) GetAllGraphs(fabric string) (response *graph_req.ResponseForGetAllGraphs, err error)

GetAllGraphs Lists all graphs stored in this GeoFabric. https://macrometa.com/docs/api#/operations/ListAllGraphs

func (GraphManager) GetAllVertices added in v1.4.1

func (c GraphManager) GetAllVertices(fabric, graphName string) (response *vertex_req.ResponseForGetAllVertices, err error)

GetAllVertices Lists all vertex collections within this graph. https://macrometa.com/do cs/api#/operations/ListVertexCollections

func (GraphManager) GetEdge added in v1.4.1

func (c GraphManager) GetEdge(fabric, graphName, collectionName, edgeKey string) (response *graph_req.ResponseForEdge, err error)

GetEdge Gets an edge from the given collection. https://macrometa.com/docs/api#/operations/GetAnEdge

func (GraphManager) GetGetAllInOutEdges added in v1.4.1

func (c GraphManager) GetGetAllInOutEdges(fabric, edgeCollectionName, vertexKey string, direction types.EdgeDirection) (response *edge_req.ResponseForGetAllInOutEdges, err error)

GetGetAllInOutEdges Returns an array of edges starting or ending in the vertex identified by vertex. direction - Select in or out direction for edges. If ANY is set, all edges are returned.

func (GraphManager) GetGraph added in v1.4.1

func (c GraphManager) GetGraph(fabric, graphName string) (response *graph_req.ResponseForGraph, err error)

GetGraph Retrieve information for a graph. Returns the edge definitions and orphan collections. https://macrometa.com/docs/api#/operations/GetAGraph

func (GraphManager) GetVertex added in v1.4.1

func (c GraphManager) GetVertex(fabric, graphName, collectionName, vertexKey string) (response *graph_req.ResponseForVertex, err error)

GetVertex Gets a vertex from the given collection. https://macrometa.com/docs/api#/operations/GetAVertex

func (GraphManager) ReplaceEdge added in v1.4.1

func (c GraphManager) ReplaceEdge(fabric, graphName, edgeCollectionName, edgeKey string, jsonReplace []byte, returnOld, returnNew bool) (response *edge_req.ResponseForReplaceEdge, err error)

ReplaceEdge Replaces the data of an edge in the collection. https://macrometa.com/docs/api#/operations/ReplaceAnEdge

func (GraphManager) ReplaceVertex added in v1.4.1

func (c GraphManager) ReplaceVertex(fabric, graphName, collectionName, vertexKey string, jsonReplace []byte, returnOld, returnNew bool) (response *graph_req.ResponseForVertex, err error)

ReplaceVertex Replaces the data of an edge in the collection.

func (GraphManager) UpdateEdge added in v1.4.1

func (c GraphManager) UpdateEdge(fabric, graphName, edgeCollectionName, edgeKey string, jsonUpdate []byte, keepNull, returnOld, returnNew bool) (response *graph_req.ResponseForEdge, err error)

func (GraphManager) UpdateVertex added in v1.4.1

func (c GraphManager) UpdateVertex(fabric, graphName, edgeCollectionName, vertexKey string, jsonUpdate []byte, returnOld, returnNew bool) (response *graph_req.ResponseForVertex, err error)

UpdateVertex Updates the data of the specific vertex in the collection. returnNew bool - Define if a presentation of the new document should be returned within the response object. returnOld bool - Define if a presentation of the deleted document should be returned within the response object.

type IndexManager added in v1.4.1

type IndexManager struct {
	// contains filtered or unexported fields
}

func NewIndexManager added in v1.4.1

func NewIndexManager(client *Client) *IndexManager

func (IndexManager) CreateFulltextIndex added in v1.4.1

func (c IndexManager) CreateFulltextIndex(fabric, collectionName, field string, minLength int) (response *index_req.IndexEntry, err error)

CreateFulltextIndex Creates fulltext index, if it does not already exist. field: Attribute to index. Must be of text format. minLength: Minimum character length of words to index.

func (IndexManager) CreateGeoIndex added in v1.4.1

func (c IndexManager) CreateGeoIndex(fabric, collectionName, field string, geoJson bool) (response *index_req.IndexEntry, err error)

CreateGeoIndex Creates a geo index. Note: Geo indexes are always sparse, meaning that documents that do not contain the index attributes or have non-numeric values in the index attributes will not be indexed.

func (IndexManager) CreateHashIndex added in v1.4.1

func (c IndexManager) CreateHashIndex(fabric, collectionName, field string, deduplicate, sparse, unique bool) (response *index_req.IndexEntry, err error)

CreateHashIndex * fields (string): an array of attribute paths. * unique: if true, then create a unique index. * sparse: if true, then create a sparse index. * deduplicate: if false, the deduplication of array values is turned off. Creates a hash index for the collection collection-name if it does not already exist. The call expects an object containing the index details. In a sparse index all documents will be excluded from the index that do not contain at least one of the specified index attributes (i.e. fields) or that have a value of null in any of the specified index attributes. Such documents will not be indexed, and not be taken into account for uniqueness checks if the unique flag is set. In a non-sparse index, these documents will be indexed (for non-present indexed attributes, a value of null will be used) and will be taken into account for uniqueness checks if the unique flag is set. Note: unique indexes on non-shard keys are not supported in a cluster. https://macrometa.com/docs/api#/operations/createIndex:hash

func (IndexManager) CreatePersistentIndex added in v1.4.1

func (c IndexManager) CreatePersistentIndex(fabric, collectionName, field string, deduplicate, sparse, unique bool) (response *index_req.IndexEntry, err error)

CreatePersistentIndex Creates a persistent index for the collection collection-name, if it does not already exist. The call expects an object containing the index details. field (string): An array of attribute paths. unique: True if the index is unique. type: Must be equal to "persistent". sparse: True if the index is sparse type. deduplicate: It controls whether inserting duplicate index values from the same document into a unique array index will lead to a unique constraint error or not. (The default is true) Note: In a sparse index all documents are excluded from the index that do not contain at least one of the specified index attributes (i.e. fields) or that have a value of null in any of the specified index attributes. Such documents are not indexed and are not taken into account for uniqueness checks if the unique flag is set. In a non-sparse index, these documents are indexed (for non-present indexed attributes, a value of null is used) and are taken into account for uniqueness checks if the unique flag is set. unique indexes on non-shard keys are not supported in a cluster. https://macrometa.com/docs/api#/operations/createIndex:persistent

func (IndexManager) CreateSkipListIndex added in v1.4.1

func (c IndexManager) CreateSkipListIndex(fabric, collectionName, field string, deduplicate, sparse, unique bool) (response *index_req.IndexEntry, err error)

CreateSkipListIndex Creates a skiplist index for the collection collection-name, if it does not already exist. The call expects an object containing the index details. fields (string): an array of attribute paths. unique: if true, then create a unique index. type: must be equal to "skiplist". sparse: if true, then create a sparse index. deduplicate: if false, the deduplication of array values is turned off.

In a sparse index all documents will be excluded from the index that do not contain at least one of the specified index attributes (i.e. fields) or that have a value of null in any of the specified index attributes. Such documents will not be indexed, and not be taken into account for uniqueness checks if the unique flag is set. In a non-sparse index, these documents will be indexed (for non-present indexed attributes, a value of null will be used) and will be taken into account for uniqueness checks if the unique flag is set. Note: unique indexes on non-shard keys are not supported in a cluster. https://macrometa.com/docs/api#/operations/createIndex:skiplist

func (IndexManager) CreateTTLIndex added in v1.4.1

func (c IndexManager) CreateTTLIndex(fabric, collectionName, field string, expireAfter int) (response *index_req.IndexEntry, err error)

CreateTTLIndex Creates a TTL index for the collection collection-name if it does not already exist. The call expects an object containing the index details. fields (string): An array with exactly one attribute path. type: Must be equal to "ttl". expireAfter: The time (in seconds) after a document's creation after which the documents count as "expired". https://macrometa.com/docs/api#/operations/createIndex:ttl

func (IndexManager) DeleteIndex added in v1.4.1

func (c IndexManager) DeleteIndex(fabric, collectionName, indexName string) (response *index_req.ResponseForDeleteIndex, err error)

DeleteIndex Remove an index. https://macrometa.com/docs/api#/operations/dropIndex

func (IndexManager) GetIndex added in v1.4.1

func (c IndexManager) GetIndex(fabric, collectionName, indexName string) (response *index_req.IndexEntry, err error)

GetIndex Fetches the information about index. https://macrometa.com/docs/api#/operations/getIndexes:handle

func (IndexManager) GetIndexes added in v1.4.1

func (c IndexManager) GetIndexes(fabric, collectionName string) (response *index_req.ResponseForGetAllIndices, err error)

GetIndexes Fetches the list of all indexes of a collection. https://macrometa.com/docs/api#/operations/getIndexes

type KVManager added in v1.4.1

type KVManager struct {
	// contains filtered or unexported fields
}

func NewKVManager added in v1.4.1

func NewKVManager(client *Client) *KVManager

func (KVManager) CountKVCollection added in v1.4.1

func (c KVManager) CountKVCollection(fabric, collectionName string) (response *kv_req.KVResult, err error)

CountKVCollection Get number of key-value pairs in collection. https://macrometa.com/docs/api#/paths/_fabric-fabric--_api-kv--collection--count/get

func (KVManager) CreateNewKVCollection added in v1.4.1

func (c KVManager) CreateNewKVCollection(fabric, collectionName string, expiration bool, options *kv_req.CreateKVOptions) (response *kv_req.KVResult, err error)

CreateNewKVCollection Create key-value collection. https://macrometa.com/docs/api#/operations/CreateNamespace

func (KVManager) DeleteKVCollection added in v1.4.1

func (c KVManager) DeleteKVCollection(fabric, collectionName string) (response *kv_req.KVResult, err error)

DeleteKVCollection Delete collection. https://macrometa.com/docs/api#/paths/_fabric-fabric--_api-kv--collection/delete

func (KVManager) DeleteKeyValuePairs added in v1.4.1

func (c KVManager) DeleteKeyValuePairs(fabric, collectionName string, keys kv_req.KeyCollection) (response *kv_req.KVPairCollection, err error)

DeleteKeyValuePairs Remove key-value collection. https://macrometa.com/docs/api#/paths/_fabric-fabric--_api-kv--collection--values/delete

func (KVManager) DeleteValue added in v1.4.1

func (c KVManager) DeleteValue(fabric, collectionName, key string) (response *kv_req.KVPair, err error)

DeleteValue Remove key-value pair. https://macrometa.com/docs/api#/paths/_fabric-fabric--_api-kv--collection--value--key/delete

func (KVManager) GetAllKVCollections added in v1.4.1

func (c KVManager) GetAllKVCollections(fabric string) (response *kv_req.KVResult, err error)

GetAllKVCollections Lists all collections. https://macrometa.com/docs/api#/paths/_fabric-fabric--_api-kv/get

func (KVManager) GetAllKeys added in v1.4.1

func (c KVManager) GetAllKeys(fabric, collectionName string, offset, limit int, order kv_req.Order) (response *kv_req.ResponseForGetAllKeys, err error)

GetAllKeys Get keys from key-value collection. https://macrometa.com/docs/api#/paths/_fabric-fabric--_api-kv--collection--keys/get

func (KVManager) GetAllValues added in v1.4.1

func (c KVManager) GetAllValues(fabric, collectionName string, offset, limit int, keys kv_req.KeyCollection) (response *kv_req.ResponseForGetAllValues, err error)

GetAllValues Get key-value pairs from collection. Optional list of keys. Max limit is 100 keys per request. https://macrometa.com/docs/api#/operations/GetValues

func (KVManager) GetValue added in v1.4.1

func (c KVManager) GetValue(fabric, collectionName, key string) (response *kv_req.KVPair, err error)

GetValue Get value from key-value collection. https://macrometa.com/docs/api#/paths/_fabric-fabric--_api-kv--collection--value--key/get

func (KVManager) SetKeyValuePairs added in v1.4.1

func (c KVManager) SetKeyValuePairs(fabric, collectionName string, kvPairs kv_req.KVPairCollection) (response *kv_req.KVPairCollection, err error)

SetKeyValuePairs Set one or more key-value pairs in key-value collection. If the input is an array of objects then key-value pairs are created in batch. If the key does not exist the key-value pairs are created. Otherwise the entry for the key is updated. Specify expiration in UTC timestamp. Max limit is 100 key-value pairs per request. https://macrometa.com/docs/api#/paths/_fabric-fabric--_api-kv--collection--value/put

func (KVManager) TruncateKVCollection added in v1.4.1

func (c KVManager) TruncateKVCollection(fabric, collectionName string) (response *kv_req.KVResult, err error)

TruncateKVCollection Remove all key-value pairs in a collection. https://macrometa.com/docs/api#/paths/_fabric-fabric--_api-kv--collection--truncate/put

type QueryManager added in v1.4.5

type QueryManager struct {
	// contains filtered or unexported fields
}

func NewQueryManager added in v1.5.1

func NewQueryManager(client *Client) *QueryManager

func (QueryManager) ExplainQuery added in v1.4.5

func (c QueryManager) ExplainQuery(fabric, query string) (res *query_req.ResponseForExplainQuery, err error)

func (QueryManager) Query added in v1.4.5

func (c QueryManager) Query(fabric, query string, bindVars map[string]interface{}, options *query_req.CursorOptions) (res *query_req.Cursor, err error)

Query Queries database / graph

func (QueryManager) ValidateQuery added in v1.4.5

func (c QueryManager) ValidateQuery(fabric, query string) (res *query_req.ResponseForValidateQuery, err error)

ValidateQuery validates a C8QL query. To actually query the database, see Query https://macrometa.com/docs/api#/operations/parseQuery

type QueryWorkerManager added in v1.5.1

type QueryWorkerManager struct {
	// contains filtered or unexported fields
}

func NewQueryWorkerManager added in v1.5.1

func NewQueryWorkerManager(client *Client) *QueryWorkerManager

func (QueryWorkerManager) CreateQueryWorker added in v1.5.1

func (c QueryWorkerManager) CreateQueryWorker(fabric, workerName, queryString, bindVars string) (res *qw_req.ResponseForQueryWorker, err error)

CreateQueryWorker Save a query for a user for a fabric. bindVars: bindVars for the query name: Name for the query value: value of the query https://macrometa.com/docs/api#/operations/SaveRestqlByName

func (QueryWorkerManager) DeleteQueryWorker added in v1.5.1

func (c QueryWorkerManager) DeleteQueryWorker(fabric, workerName string) (err error)

DeleteQueryWorker Delete a query under the given fabric. https://macrometa.com/docs/api#/operations/DeleteRestqlByName

func (QueryWorkerManager) ReadAllQueryWorkers added in v1.5.1

func (c QueryWorkerManager) ReadAllQueryWorkers(fabric string) (res *qw_req.ResponseForReadAllQueryWorkers, err error)

ReadAllQueryWorkers Get list of saved queries for the fabric. https://macrometa.com/docs/api#/operations/ListRestqlAssociatedWithCurrentUser

func (QueryWorkerManager) RunQueryWorker added in v1.5.1

func (c QueryWorkerManager) RunQueryWorker(fabric, workerName, bindVars string) (res *query_req.Cursor, err error)

RunQueryWorker Run a saved query for a given fabric. If there are more that 100 records, the hasMore flag is set to true. Note this client fetches all additional records, merges them, and returns just one combined result. https://macrometa.com/docs/api#/operations/ExecuteRestqlByName

func (QueryWorkerManager) UpdateQueryWorker added in v1.5.1

func (c QueryWorkerManager) UpdateQueryWorker(fabric, workerName, queryString, bindVars string) (res *qw_req.ResponseForQueryWorker, err error)

UpdateQueryWorker Update a saved query for a fabric. https://macrometa.com/docs/api#/operations/UpdateRestqlByName

type Response

type Response struct {
	Result     interface{} `json:"result,omitempty"`
	RawMessage jsoniter.RawMessage
	Error      string `json:"error,omitempty"`
	Success    bool   `json:"success"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL