go-driver icon indicating copy to clipboard operation
go-driver copied to clipboard

How to use velocypack in go-driver?

Open curiosport opened this issue 3 years ago • 7 comments

I am currently using the json schema but it does not support binary types so I found I could use velocypack however I can't find any examples of how to use it and the package documentation literally says nothing about how to use it.

Can someone please give me an example of how to use it with go?

curiosport avatar Jul 29 '22 11:07 curiosport

There is support for velocypack already - you need to pass additional ContentType field during connection creation:

	conn, err := http.NewConnection(http.ConnectionConfig{
		Endpoints: []string{"http://localhost:8529"},
                ContentType: driver.ContentTypeVelocypack,
	})

jwierzbo avatar Aug 02 '22 12:08 jwierzbo

@jwierzbo This doesn't solve my problem, it's just that I don't know which Velocypack format to use.

In other words, I know how to use a json schema, I just create a .json file with the schema, read it and pass a string to the driver and it works:

modelScheme := &driver.CollectionSchemaOptions{
  Rule:  json.RawMessage(jsonScheme),
  Level: driver.CollectionSchemaLevelStrict,
  Message: fmt.Sprintf(
	  "The document does not meet the requirements of the collection \"%s\"",
	  col.Name(),
  ),
}

But what is the format of a Velocypack for use in the Rule field?

curiosport avatar Aug 02 '22 12:08 curiosport

@curiosport here is the doc for schema: https://www.arangodb.com/docs/3.9/data-modeling-documents-schema-validation.html#enable-schema-validation-for-a-collection

jwierzbo avatar Aug 02 '22 13:08 jwierzbo

@curiosport here is the doc for schema: https://www.arangodb.com/docs/3.9/data-modeling-documents-schema-validation.html#enable-schema-validation-for-a-collection

But that's for json schema, and I said I do know how to use it, are you telling me velocypack uses the same schema as json?

curiosport avatar Aug 02 '22 13:08 curiosport

We just change the data protocol from json to velocypack, so the rest should stay same. Once you set correct encoding the rest is handled by the go-driver: https://github.com/arangodb/go-driver/blob/19f1f26f2deb77a74992ba7b8c4b4ee43256bf0c/http/connection.go#L218-L228

jwierzbo avatar Aug 02 '22 13:08 jwierzbo

This is not valid in json schema: "type": "byte",

So if I activate velocypack that field will be correct? or how do I specify that a field is binary?

curiosport avatar Aug 02 '22 14:08 curiosport

You should use only ContentType: driver.ContentTypeVelocypack, as I've described above. Then the whole request will be sent in velocypack format instead JSON, but the rest of the request stay the same. You don't need to apply any additional adjustments in schema

jwierzbo avatar Aug 03 '22 08:08 jwierzbo