Documentation
¶
Index ¶
- func Close()
- func EdgeTypes() []string
- func HasNode(id primitive.TypedID) bool
- func NodeTypes() []string
- func RangeEdgeTypes(edgeType primitive.Type, fn func(e *primitive.Edge) bool)
- func RangeEdges(fn func(e *primitive.Edge) bool)
- func RangeNodeTypes(typ primitive.Type, fn func(n *Node) bool)
- func RangeNodes(fn func(n *Node) bool)
- type Node
- func (n *Node) Connect(node *Node, relationship string, mutual bool) error
- func (n *Node) Del(key string)
- func (n *Node) EdgesFrom(fn func(e *primitive.Edge) bool)
- func (n *Node) EdgesTo(fn func(e *primitive.Edge) bool)
- func (n *Node) FromJSON(bits []byte) error
- func (n *Node) Get(key string) interface{}
- func (n *Node) GetBool(key string) bool
- func (n *Node) GetInt(key string) int
- func (n *Node) GetString(key string) string
- func (n *Node) JSON() ([]byte, error)
- func (n *Node) Patch(data map[string]interface{})
- func (n *Node) Range(fn func(key string, value interface{}) bool)
- func (n *Node) Remove()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EdgeTypes ¶
func EdgeTypes() []string
EdgeTypes returns the types of relationships/edges/connections in the graph
func RangeEdgeTypes ¶
RangeEdgeTypes iterates over edges/connections of a given type until the iterator returns false
func RangeEdges ¶
RangeEdges iterates over all edges/connections until the iterator returns false
func RangeNodeTypes ¶
RangeNodeTypes iterates over nodes of a given type until the iterator returns false
func RangeNodes ¶
RangeNodes iterates over all nodes until the iterator returns false
Types ¶
type Node ¶
Node is the most basic element in the graph. Node's may be connected with one another via edges to represent relationships
func NewNode ¶
NewNode creates a new node in the global, in-memory graph. If an id is not provided, a random uuid will be assigned.
Example ¶
package main
import (
"fmt"
"github.com/autom8ter/dagger"
"github.com/autom8ter/dagger/primitive"
"log"
"time"
)
func main() {
coleman = dagger.NewNode("user", fmt.Sprintf("cword_%v", time.Now().UnixNano()), map[string]interface{}{
"name": "coleman",
})
tyler = dagger.NewNode("user", fmt.Sprintf("twash_%v", time.Now().UnixNano()), map[string]interface{}{
"name": "tyler",
})
sarah = dagger.NewNode("user", fmt.Sprintf("swash_%v", time.Now().UnixNano()), map[string]interface{}{
"name": "sarah",
})
lacee = dagger.NewNode("user", fmt.Sprintf("ljans_%v", time.Now().UnixNano()), map[string]interface{}{
"name": "lacee",
})
// random id will be generated if one isn't provided
charlie = dagger.NewNode("dog", "", map[string]interface{}{
"name": "charlie",
"weight": 25,
})
if err := coleman.Connect(tyler, "friend", true); err != nil {
exitErr(err)
}
if err := sarah.Connect(lacee, "friend", true); err != nil {
exitErr(err)
}
if err := coleman.Connect(lacee, "fiance", true); err != nil {
exitErr(err)
}
if err := tyler.Connect(lacee, "wife", true); err != nil {
exitErr(err)
}
if err := coleman.Connect(charlie, "pet", false); err != nil {
exitErr(err)
}
if err := lacee.Connect(charlie, "pet", false); err != nil {
exitErr(err)
}
if err := charlie.Connect(lacee, "owner", false); err != nil {
exitErr(err)
}
if err := charlie.Connect(coleman, "owner", false); err != nil {
exitErr(err)
}
charlie.Patch(map[string]interface{}{
"weight": 19,
})
if charlie.GetInt("weight") != 19 {
exit("expected charlie's weight to be 19!")
}
// check to make sure edge is patched
coleman.EdgesFrom(func(e *primitive.Edge) bool {
if e.Type() == "pet" && e.GetString("name") == "charlie" {
if e.To.GetInt("weight") != 19 {
exit("failed to patch charlie's weight")
}
}
return true
})
if coleman.GetString("name") != "coleman" {
exit("expected name to be coleman")
}
// remove from graph
charlie.Remove()
// no longer in graph
if dagger.HasNode(charlie) {
exit("failed to delete node - (charlie)")
}
// check to make sure edge no longer exists(cascade)
coleman.EdgesFrom(func(e *primitive.Edge) bool {
if e.Type() == "pet" && e.GetString("name") == "charlie" {
exit("failed to delete node - (charlie)")
}
return true
})
// check to make sure edge no longer exists(cascade)
lacee.EdgesFrom(func(e *primitive.Edge) bool {
if e.Type() == "pet" && e.GetString("name") == "charlie" {
exit("failed to delete node - (charlie)")
}
return true
})
}
func exit(msg string) {
log.Fatal(msg)
}
func exitErr(err error) {
log.Fatal(err)
}
Output:
func (*Node) Connect ¶
Connect creates a connection/edge between the two nodes with the given relationship type if mutual = true, the connection is doubly linked - (facebook is mutual, instagram is not)
func (*Node) Get ¶ added in v0.1.0
Get gets an empty interface value(any value type) from the nodes attributes(if it exists)
func (*Node) GetBool ¶ added in v0.1.0
GetBool gets a bool value from the nodes attributes(if it exists)
func (*Node) GetInt ¶ added in v0.1.0
GetInt gets an int value from the nodes attributes(if it exists)
func (*Node) GetString ¶ added in v0.1.0
GetString gets a string value from the nodes attributes(if it exists)