github.com/cayleygraph/cayley@v0.7.7/examples/hello_world/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  
     7  	"github.com/cayleygraph/cayley"
     8  	"github.com/cayleygraph/quad"
     9  )
    10  
    11  func main() {
    12  	// Create a brand new graph
    13  	store, err := cayley.NewMemoryGraph()
    14  	if err != nil {
    15  		log.Fatalln(err)
    16  	}
    17  
    18  	store.AddQuad(quad.Make("phrase of the day", "is of course", "Hello World!", nil))
    19  
    20  	// Now we create the path, to get to our data
    21  	p := cayley.StartPath(store, quad.String("phrase of the day")).Out(quad.String("is of course"))
    22  
    23  	// Now we iterate over results. Arguments:
    24  	// 1. Optional context used for cancellation.
    25  	// 2. Quad store, but we can omit it because we have already built path with it.
    26  	err = p.Iterate(nil).EachValue(nil, func(value quad.Value) {
    27  		nativeValue := quad.NativeOf(value) // this converts RDF values to normal Go types
    28  		fmt.Println(nativeValue)
    29  	})
    30  	if err != nil {
    31  		log.Fatalln(err)
    32  	}
    33  }