Documentation
¶
Index ¶
- func AnyType() primitive.Type
- func Close()
- func DefaultType() primitive.Type
- func DelEdge(id primitive.TypedID)
- func DelNode(id primitive.TypedID)
- func EdgeCount() int
- func EdgeTypes() []string
- func ExportJSON(w io.Writer) error
- func HasEdge(id primitive.TypedID) bool
- func HasNode(id primitive.TypedID) bool
- func ImportJSON(r io.Reader) error
- func NodeCount() int
- func NodeTypes() []string
- func RandomID() primitive.ID
- func RangeEdgeTypes(edgeType primitive.Type, fn func(e *Edge) bool)
- func RangeEdges(fn func(e *Edge) bool)
- func RangeNodeTypes(typ primitive.Type, fn func(n *Node) bool)
- func RangeNodes(fn func(n *Node) bool)
- func StringID(id string) primitive.ID
- func StringType(typ string) primitive.Type
- type Edge
- func (e *Edge) Del(key string)
- func (e *Edge) From() *Node
- func (e *Edge) FromJSON(bits []byte) error
- func (e *Edge) Get(key string) interface{}
- func (e *Edge) GetBool(key string) bool
- func (e *Edge) GetInt(key string) int
- func (e *Edge) GetString(key string) string
- func (e *Edge) JSON() ([]byte, error)
- func (e *Edge) Node() *Node
- func (e *Edge) Patch(data map[string]interface{})
- func (e *Edge) Range(fn func(key string, value interface{}) bool)
- func (e *Edge) To() *Node
- type ForeignKey
- type Node
- func (n *Node) Connect(nodeID primitive.TypedID, relationship string, mutual bool) (*Edge, error)
- func (n *Node) Del(key string)
- func (n *Node) EdgesFrom(edgeType primitive.Type, fn func(edge *Edge) bool)
- func (n *Node) EdgesTo(edgeType primitive.Type, fn func(e *Edge) bool)
- func (n *Node) FilterEdgesFrom(edgeType primitive.Type, filter func(e *Edge) bool) []*Edge
- func (n *Node) FilterEdgesTo(edgeType primitive.Type, filter func(e *Edge) bool) []*Edge
- 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) Raw() map[string]interface{}
- func (n *Node) Remove()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultType ¶ added in v0.11.0
func EdgeCount ¶ added in v0.1.1
func EdgeCount() int
EdgeCount returns the total number of edges in the graph
func EdgeTypes ¶
func EdgeTypes() []string
EdgeTypes returns the types of relationships/edges/connections in the graph
func ExportJSON ¶ added in v0.1.1
ExportJSON exports the graph as a json blob into the io Writer
func HasEdge ¶ added in v0.11.0
HasEdge returns true if an edge with the typed ID exists in the graph
func ImportJSON ¶ added in v0.1.1
ImportJSON imports the json blob into the graph from the io Reader
func NodeCount ¶ added in v0.1.1
func NodeCount() int
NodeCount returns the total number of nodes 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
func StringType ¶ added in v0.1.2
Types ¶
type Edge ¶ added in v0.1.1
Edge is an edge in the directed graph. It represents a relationship between two nodes.
func (*Edge) Get ¶ added in v0.1.1
Get gets an empty interface value(any value type) from the edges attributes(if it exists)
func (*Edge) GetBool ¶ added in v0.1.1
GetBool gets a bool value from the edges attributes(if it exists)
func (*Edge) GetInt ¶ added in v0.1.1
GetInt gets an int value from the edges attributes(if it exists)
func (*Edge) GetString ¶ added in v0.1.1
GetString gets a string value from the edges attributes(if it exists)
type ForeignKey ¶ added in v0.1.1
ForeignKey satisfies primitive.TypedID interface
func (*ForeignKey) ID ¶ added in v0.11.0
func (f *ForeignKey) ID() string
func (*ForeignKey) Path ¶ added in v0.11.0
func (f *ForeignKey) Path() string
func (*ForeignKey) Type ¶ added in v0.11.0
func (f *ForeignKey) Type() string
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"
"log"
)
func main() {
coleman = dagger.NewNode(map[string]interface{}{
"_type": "user",
"name": "coleman",
})
tyler = dagger.NewNode(map[string]interface{}{
"_type": "user",
"name": "coleman",
})
sarah = dagger.NewNode(map[string]interface{}{
"_type": "user",
"name": "sarah",
})
lacee = dagger.NewNode(map[string]interface{}{
"_type": "user",
"name": "lacee",
})
charlie = dagger.NewNode(map[string]interface{}{
"_type": "dog",
"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(sarah, "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(dagger.AnyType(), func(e *dagger.Edge) bool {
if e.Type() == "pet" {
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(dagger.AnyType(), func(e *dagger.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(dagger.AnyType(), func(e *dagger.Edge) bool {
if e.Type() == "pet" && e.GetString("name") == "charlie" {
exit("failed to delete node - (charlie)")
}
return true
})
fmt.Printf("registered node types = %v\n", dagger.NodeTypes())
fmt.Printf("registered edge types = %v\n", dagger.EdgeTypes())
}
func exit(msg string) {
log.Fatal(msg)
}
func exitErr(err error) {
log.Fatal(err)
}
Output: registered node types = [dog user] registered edge types = [fiance friend owner pet wife]
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) FilterEdgesFrom ¶ added in v0.11.0
FilterEdgesFrom returns an array of edges that point from the node that pass the filter
func (*Node) FilterEdgesTo ¶ added in v0.11.0
FilterEdgesTo returns an array of edges that point to the node that pass the filter
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)
