db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package grit/db implements the basic CRUD operations used to interact with grit data. All operations are atomic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	DB       *sql.DB
	Filename string
}

func New

func New(filename string) (*Database, error)

func (*Database) CheckNode

func (d *Database) CheckNode(nodeID int64) error

CheckNode marks the node as completed, along with all its direct and indirect successors. The rest of the multitree is updated to reflect the change.

func (*Database) Close

func (d *Database) Close() error

func (*Database) CreateChildOfDateNode

func (d *Database) CreateChildOfDateNode(date, name string) (int64, error)

CreateChildOfDateNode atomically creates a node and links the date node to it. Date node is created if it doesn't exist.

func (d *Database) CreateLink(originID, destID int64) (int64, error)

func (*Database) CreateLinkFromDateNode

func (d *Database) CreateLinkFromDateNode(date string, destID int64) (int64, error)

CreateLinkFromDateNode atomically creates an link with date node as the origin. Date node is automatically created if it doesn't exist.

func (*Database) CreateNode

func (d *Database) CreateNode(name string, parentID int64) (int64, error)

CreateNode creates a node and returns its ID. It updates the status of other nodes in the multitree if needed.

func (*Database) CreateTree

func (d *Database) CreateTree(node *multitree.Node, parentID int64) (int64, error)

CreateTree saves an entire tree in the database and returns the root ID. It updates the status of other nodes in the multitree to reflect the change.

func (*Database) CreateTreeAsChildOfDateNode

func (d *Database) CreateTreeAsChildOfDateNode(date string, node *multitree.Node) (int64, error)

CreateTreeAsChildOfDateNode atomically creates a tree and links the date node to its root. Date node is created if it doesn't exist.

func (*Database) DeleteLinkByEndpoints

func (d *Database) DeleteLinkByEndpoints(originID, destID int64) error

func (*Database) DeleteNode

func (d *Database) DeleteNode(id int64) ([]*multitree.Node, error)

DeleteNode deletes a single node and propagates the change to the rest of the multitree. It returns the node's orphaned successors.

func (*Database) DeleteNodeRecursive

func (d *Database) DeleteNodeRecursive(id int64) ([]*multitree.Node, error)

DeleteNodeRecursive deletes the tree rooted at the given node and updates the multitree. Nodes that have parents outside of this tree are preserved. It returns a slice of all deleted nodes.

func (*Database) GetGraph

func (d *Database) GetGraph(nodeID int64) (*multitree.Node, error)

GetGraph builds a multitree using Breadth-First Search, and returns the requested node as part of the multitree.

func (d *Database) GetLink(linkID int64) (*multitree.Link, error)

func (*Database) GetLinkByEndpoints

func (d *Database) GetLinkByEndpoints(originID, destID int64) (*multitree.Link, error)

func (*Database) GetLinksByNodeID

func (d *Database) GetLinksByNodeID(nodeID int64) ([]*multitree.Link, error)

GetLinksByNodeID gets the node's incoming and outcoming links.

func (*Database) GetNode

func (d *Database) GetNode(id int64) (*multitree.Node, error)

GetNode returns the node with the given id, or nil if it doesn't exist.

func (*Database) GetNodeByAlias

func (d *Database) GetNodeByAlias(alias string) (*multitree.Node, error)

GetNode returns the node with the given alias, or nil if it doesn't exist.

func (*Database) GetNodeByName

func (d *Database) GetNodeByName(name string) (*multitree.Node, error)

GetNode returns the node with the given name, or nil if it doesn't exist.

func (*Database) GetRoots

func (d *Database) GetRoots() ([]*multitree.Node, error)

GetRoots returns a slice of nodes that have no predecessors.

func (*Database) Open

func (d *Database) Open(fp string) error

func (*Database) RenameNode

func (d *Database) RenameNode(nodeID int64, name string) error

func (*Database) SetAlias

func (d *Database) SetAlias(nodeID int64, alias string) error

func (*Database) UncheckNode

func (d *Database) UncheckNode(nodeID int64) error

UncheckNode sets the node's status to inactive, along with all its direct and indirect successors. The rest of the multitree is updated to reflect the change.

Jump to

Keyboard shortcuts

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