github.com/cayleygraph/cayley@v0.7.7/examples/transaction/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  	// To see how most of this works, see hello_world -- this just add in a transaction
    13  	store, err := cayley.NewMemoryGraph()
    14  	if err != nil {
    15  		log.Fatalln(err)
    16  	}
    17  
    18  	// Create a transaction of work to do
    19  	// NOTE: the transaction is independent of the storage type, so comes from cayley rather than store
    20  	t := cayley.NewTransaction()
    21  	t.AddQuad(quad.Make("food", "is", "good", nil))
    22  	t.AddQuad(quad.Make("phrase of the day", "is of course", "Hello World!", nil))
    23  	t.AddQuad(quad.Make("cats", "are", "awesome", nil))
    24  	t.AddQuad(quad.Make("cats", "are", "scary", nil))
    25  	t.AddQuad(quad.Make("cats", "want to", "kill you", nil))
    26  
    27  	// Apply the transaction
    28  	err = store.ApplyTransaction(t)
    29  	if err != nil {
    30  		log.Fatalln(err)
    31  	}
    32  
    33  	p := cayley.StartPath(store, quad.String("cats")).Out(quad.String("are"))
    34  
    35  	err = p.Iterate(nil).EachValue(nil, func(v quad.Value) {
    36  		fmt.Println("cats are", v.Native())
    37  	})
    38  	if err != nil {
    39  		log.Fatalln(err)
    40  	}
    41  }