go-driver
go-driver copied to clipboard
How to use velocypack in go-driver?
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?
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 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 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
@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?
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
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?
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