Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmosDB support? #42

Open
Kubera2017 opened this issue Feb 10, 2021 · 2 comments
Open

CosmosDB support? #42

Kubera2017 opened this issue Feb 10, 2021 · 2 comments

Comments

@Kubera2017
Copy link

Hello, does this library support CosmosDB?

I tried, actually it needs GraphSONSerializersV2d0 instead of V3, I used grammes.WithGremlinVersion(2) for that, vertices are added, but retreival queries don't work, it returns empty labels and IDs. This is test code:

package main

import (
	"fmt"
	"log"

	"github.com/northwesternmutual/grammes"
)

func main() {
	cosmosdb_account := "g123"
	cosmosdb_password := "J7q==" // Primary key from Keys
	cosmosdb_database := "db"    // In Data Explorer, need to create yours
	cosmosdb_graph := "test" // In Data Explorer, need to create yours

	cosmosdb_partition_key := "partition_key" // the same as you set when creating the graph in Data Explorer
	cosmosdb_partition_value := "1"

	host := "wss://" + cosmosdb_account + ".gremlin.cosmosdb.azure.com:443/"
	username := "/dbs/" + cosmosdb_database + "/colls/" + cosmosdb_graph
	password := cosmosdb_password

	client, err := grammes.DialWithWebSocket(host,
		grammes.WithAuthUserPass(username, password),
		grammes.WithGremlinVersion(2),
	)
	if err != nil {
		log.Fatal(err.Error())
	}

	_, err = client.AddVertex("test", cosmosdb_partition_key, cosmosdb_partition_value)
	if err != nil {
		log.Fatal("failed to add vertex", err.Error())
	}

	g := grammes.Traversal()
	vertices, err := client.VerticesByQuery(g.V())
	if err != nil {
		log.Fatal("Couldn't gather vertices", err.Error())
	}

	for _, vertex := range vertices {
		fmt.Println(vertex.Label(), vertex.ID())
	}

}
@zmmille2
Copy link

Thanks for pointing out the v2 here, saved me some work.

I wasn't able to get your code to work exactly, but what's the VerticiesByQuery method exactly? Do you mean to just run ExecuteQuery here?

	g := grammes.Traversal()
	vertices, err := client.ExecuteQuery(g.V())
	if err != nil {
		log.Fatal("Couldn't gather vertices", err.Error())
	}

	for _, vertex := range vertices {
		fmt.Println(string(vertex))
	}

seems to work just fine.

@Kubera2017
Copy link
Author

Kubera2017 commented Mar 30, 2021

That's good that it works, but VerticesByQuery returns array of vertices already []model.Vertex, but ExecuteQuery returns raw result. This means you will unable to use the library API.

func (c *getVertexQueryManager) VerticesByQuery(query query.Query) ([]model.Vertex, error) {

func (m *queryManager) ExecuteQuery(query query.Query) ([][]byte, error) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants