Quickstart as Library
Currently, Cayley supports being used as a Go library for other projects. To use it in such a way, here's a quick example:
package main
import (
func main() {
// Create a brand new graph
store, err := cayley.NewMemoryGraph()
if err != nil {
store.AddQuad(quad.Make("phrase of the day", "is of course", "Hello World!", nil))
// Now we create the path, to get to our data
p := cayley.StartPath(store, quad.String("phrase of the day")).Out(quad.String("is of course"))
// Now we iterate over results. Arguments:
// 1. Optional context used for cancellation.
// 2. Flag to optimize query before execution.
// 3. Quad store, but we can omit it because we have already built path with it.
err = p.Iterate(nil).EachValue(nil, func(value quad.Value){
nativeValue := quad.NativeOf(value) // this converts RDF values to normal Go types
if err != nil {
To use other backends, you can empty-import them, eg
import _ ""
And use them with a call like
import ""
func open() {
// Initialize the database
graph.InitQuadStore("bolt", path, nil)
// Open and use the database
cayley.NewGraph("bolt", path, nil)
More runnable examples are available in examples folder.
Copy link