memory

package
v0.0.0-...-c7fa441 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultLabel is the default graph label.
	DefaultLabel = "MemoryGraph"
	// MemoryDSN is the in-memory data source name.
	MemoryDSN = ":memory:"
)

Variables

View Source
var (
	// ErrDBClosed is returned if attempting a transaction on closed DB.
	ErrDBClosed = errors.New("ErrDBClosed")
)

Functions

This section is empty.

Types

type DB

type DB struct {
	// Datasource name.
	DSN string
	// Closed flag for DB operations.
	Closed bool

	*sync.RWMutex
	// contains filtered or unexported fields
}

DB is an in-memory graph store.

func NewDB

func NewDB(dsn string) (*DB, error)

NewDB returns a new instance of DB associated with the given datasource name. NOTE: dsn is either ":memory:" or a path to a directory that stores graphs.

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context) (*Tx, error)

Do creates a DB operation.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) Open

func (db *DB) Open() (err error)

Open opens the database connection.

type EdgeService

type EdgeService struct {
	// contains filtered or unexported fields
}

EdgeService lets you manage graph edges.

func NewEdgeService

func NewEdgeService(db *DB) (*EdgeService, error)

NewEdgeService creates an instance of EdgeService and returns it. Nodes managed by the node service belong to the graph with the given uid.

func (*EdgeService) CreateEdge

func (es *EdgeService) CreateEdge(ctx context.Context, uid string, e *api.Edge) error

CreateEdge creates a new edge.

func (*EdgeService) DeleteEdge

func (es *EdgeService) DeleteEdge(ctx context.Context, guid, euid string) error

DeleteEdge permanently removes an edge by UID.

func (*EdgeService) DeleteEdgeBetween

func (es *EdgeService) DeleteEdgeBetween(ctx context.Context, guid string, source, target int64) error

DeleteEdgeBetween permanently deletes all edges between source and target nodes.

func (*EdgeService) FindEdgeByUID

func (es *EdgeService) FindEdgeByUID(ctx context.Context, guid, euid string) (*api.Edge, error)

FindEdgeByUID returns a single edge with the given id.

func (*EdgeService) FindEdges

func (es *EdgeService) FindEdges(ctx context.Context, guid string, filter api.EdgeFilter) ([]*api.Edge, int, error)

FindEdges returns all edges matching the filter. It also returns a count of total matching edges which may differ from the number of returned edges if the Limit field is set.

func (*EdgeService) UpdateEdgeBetween

func (es *EdgeService) UpdateEdgeBetween(ctx context.Context, guid string, source, target int64, update api.EdgeUpdate) (*api.Edge, error)

UpdateEdgeBetween updates an edge between two nodes.

type GraphService

type GraphService struct {
	// contains filtered or unexported fields
}

GraphService lets you manage graphs.

func NewGraphService

func NewGraphService(db *DB) (*GraphService, error)

NewGraphService creates an instance of GraphService and returns it.

func (*GraphService) CreateGraph

func (gs *GraphService) CreateGraph(ctx context.Context, g *api.Graph) error

CreateGraph creates a new graph.

func (*GraphService) DeleteGraph

func (gs *GraphService) DeleteGraph(ctx context.Context, uid string) error

DeleteGraph permanently removes a graph by ID.

func (*GraphService) FindGraphByUID

func (gs *GraphService) FindGraphByUID(ctx context.Context, uid string) (*api.Graph, error)

FindGraphByUID returns a single graph with the given uid.

func (*GraphService) FindGraphs

func (gs *GraphService) FindGraphs(ctx context.Context, filter api.GraphFilter) ([]*api.Graph, int, error)

FindGraphs returns all graphs matching the filter. It also returns a count of total matching graphs which may differ from the number of returned graphs if the Limit field is set.

func (*GraphService) UpdateGraph

func (gs *GraphService) UpdateGraph(ctx context.Context, uid string, update api.GraphUpdate) (*api.Graph, error)

UpdateGraph updates an existing graph by ID.

type NodeService

type NodeService struct {
	// contains filtered or unexported fields
}

NodeService manages graph nodes.

func NewNodeService

func NewNodeService(db *DB) (*NodeService, error)

NewNodeService creates an instance of NodeService and returns it. Nodes managed by the node service belong to the graph with the given uid.

func (*NodeService) CreateNode

func (ns *NodeService) CreateNode(ctx context.Context, uid string, n *api.Node) error

CreateNode creates a new node.

func (*NodeService) DeleteNodeByID

func (ns *NodeService) DeleteNodeByID(ctx context.Context, uid string, id int64) error

DeleteNodeByID permanently removes a node by ID. It automatically removes removed node's incoming and outgoing edges.

func (*NodeService) DeleteNodeByUID

func (ns *NodeService) DeleteNodeByUID(ctx context.Context, guid, nuid string) error

DeleteNodeByUID permanently removes a node by UID. It automatically removes removed node's incoming and outgoing edges.

func (*NodeService) FindNodeByID

func (ns *NodeService) FindNodeByID(ctx context.Context, uid string, id int64) (*api.Node, error)

FindNodeByID returns a single node with the given id.

func (*NodeService) FindNodeByUID

func (ns *NodeService) FindNodeByUID(ctx context.Context, guid, nuid string) (*api.Node, error)

FindNodeByID returns a single node with the given uid.

func (*NodeService) FindNodes

func (ns *NodeService) FindNodes(ctx context.Context, uid string, filter api.NodeFilter) ([]*api.Node, int, error)

FindNodes returns all nodes matching the filter. It also returns a count of total matching nodes which may differ from the number of returned nodes if the Limit field is set.

func (*NodeService) UpdateNode

func (ns *NodeService) UpdateNode(ctx context.Context, uid string, id int64, update api.NodeUpdate) (*api.Node, error)

UpdateNode updates an existing node by ID.

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Tx wraps DB to provide graph CRUD operations.

func (*Tx) CreateEdge

func (t *Tx) CreateEdge(ctx context.Context, uid string, e *api.Edge) error

CreateEdge adds a new node to graph.

func (*Tx) CreateGraph

func (t *Tx) CreateGraph(ctx context.Context, g *api.Graph) error

CreateGraph creates a new graph and returns it.

func (*Tx) CreateNode

func (t *Tx) CreateNode(ctx context.Context, uid string, n *api.Node) error

CreateNode adds a new node to graph.

func (*Tx) DeleteEdge

func (t *Tx) DeleteEdge(ctx context.Context, guid, euid string) error

DeleteEdge deletes edge with the given uid from graph.

func (*Tx) DeleteEdgeBetween

func (t *Tx) DeleteEdgeBetween(ctx context.Context, uid string, source, target int64) error

DeleteEdgeBetween deletes all edges between source and target nodes.

func (*Tx) DeleteGraph

func (t *Tx) DeleteGraph(ctx context.Context, uid string) error

DeleteGraph deletes graph from db.

func (*Tx) DeleteNodeByID

func (t *Tx) DeleteNodeByID(ctx context.Context, uid string, id int64) error

DeleteNode deletes node from graph.

func (*Tx) DeleteNodeByUID

func (t *Tx) DeleteNodeByUID(ctx context.Context, guid, nuid string) error

DeleteNode deletes node from graph.

func (*Tx) FindEdgeByUID

func (t *Tx) FindEdgeByUID(ctx context.Context, guid, euid string) (*TxEdge, error)

FindEdgeByUID returns edge with the given UID. It returns error if the edge with the given uid could not be found.

func (*Tx) FindEdges

func (t *Tx) FindEdges(ctx context.Context, uid string, filter api.EdgeFilter) ([]*TxEdge, int, error)

FindEdges returns all graph nodes matching the filter.

func (*Tx) FindGraphByUID

func (t *Tx) FindGraphByUID(ctx context.Context, uid string) (*memory.Graph, error)

FindGraphByUID returns graph with the given UID. It returns error if the graph with the given uid could not be found.

func (*Tx) FindGraphs

func (t *Tx) FindGraphs(ctx context.Context, filter api.GraphFilter) ([]*memory.Graph, int, error)

FindGraphs returns all graphs matching the filter.

func (*Tx) FindNodeByID

func (t *Tx) FindNodeByID(ctx context.Context, uid string, id int64) (*TxNode, error)

FindNodeByID returns node with the given ID. It returns error if the node with the given id could not be found.

func (*Tx) FindNodeByUID

func (t *Tx) FindNodeByUID(ctx context.Context, guid, uid string) (*TxNode, error)

FindNodeByUID returns node with the given UID. It returns error if the node with the given uid could not be found.

func (*Tx) FindNodes

func (t *Tx) FindNodes(ctx context.Context, uid string, filter api.NodeFilter) ([]*TxNode, int, error)

FindNodes returns all graph nodes matching the filter.

func (*Tx) UpdateEdgeBetween

func (t *Tx) UpdateEdgeBetween(ctx context.Context, uid string, src, trgt int64, update api.EdgeUpdate) (*TxEdge, error)

UpdateEdgeBetween updates edge between two nodes.

func (*Tx) UpdateGraph

func (t *Tx) UpdateGraph(ctx context.Context, uid string, update api.GraphUpdate) (*memory.Graph, error)

UpdateGraph updates graph in db.

func (*Tx) UpdateNode

func (t *Tx) UpdateNode(ctx context.Context, uid string, id int64, update api.NodeUpdate) (*TxNode, error)

UpdateNode updates node.

type TxEdge

type TxEdge struct {
	*memory.Edge
}

TxEdge wraps memory.Edge

type TxNode

type TxNode struct {
	*memory.Node
	DegIn  int
	DegOut int
}

TxNode wraps memory.Node

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL