core

package
v0.0.0-...-88b10d6 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RootParentsFieldName is the name of the parents field on a root.
	RootParentsFieldName = "Parents"
	// RootSchemaFieldName is the name of the schema field on a root.
	RootSchemaFieldName = "Schema"
	// RootCollectionsFieldName is the name of the collections field on a root.
	RootCollectionsFieldName = "Collections"
	// CollectionDocumentsFieldName is the name of the documents field on a collection.
	CollectionDocumentsFieldName = "Documents"
)

Variables

This section is empty.

Functions

func BuildCollectionNode

func BuildCollectionNode() (datamodel.Node, error)

BuildCollectionNode returns a new collection node with default field values.

func BuildRootCollectionsNode

func BuildRootCollectionsNode(ctx context.Context, store *Store, s *ast.Schema) (datamodel.Node, error)

BuildRootCollectionsNode returns a new collections field node containing the collections defined in the given schema.

func BuildRootNode

func BuildRootNode(ctx context.Context, store *Store, schema string) (datamodel.Node, error)

BuildRootNode returns a new root node with the collections defined in the given schema.

func BuildRootParentsNode

func BuildRootParentsNode(parents ...datamodel.Link) (datamodel.Node, error)

BuildRoootParentsNode returns a new parents field node node containing the given parent links.

func CollectionPath

func CollectionPath(collection string) datamodel.Path

CollectionPath returns the path for the given collection.

func DocumentPath

func DocumentPath(collection string, id string) datamodel.Path

DocumentPath returns the path for the document in the given collection with the given id.

func DocumentsPath

func DocumentsPath(collection string) datamodel.Path

DocumentsPath returns the path for the documents map of the given collection.

func Dump

func Dump(ctx context.Context, store *Store, rootLink datamodel.Link) (map[string][]string, error)

Dump returns a map of collections to document ids.

This function is primarily used for testing.

func Export

func Export(ctx context.Context, store *Store, rootLink datamodel.Link, out io.Writer) error

Export writes a CAR containing the DAG starting from the given root link to the given io.Writer.

func Independents

func Independents(ctx context.Context, store *Store, links []datamodel.Link) ([]datamodel.Link, error)

Independents returns a list links where each entry is not an ancestor of any other entry.

func IsAncestor

func IsAncestor(ctx context.Context, store *Store, oldLink, newLink datamodel.Link) (bool, error)

IsAncestor returns true if the old link is an ancestor of the new link.

func MergeBase

func MergeBase(ctx context.Context, store *Store, oldLink, newLink datamodel.Link) ([]datamodel.Link, error)

MergeBase returns the best common ancestor for merging the two given links.

Types

type DocumentIterator

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

DocumentIterator iterates over all documents in a collection.

func (*DocumentIterator) Done

func (i *DocumentIterator) Done() bool

Done returns true if the iterator has no items left.

func (*DocumentIterator) Next

Next returns the next document id and document node from the iterator.

type ParentIterator

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

ParentIterator iterates over all parents of a root node.

func (*ParentIterator) Done

func (i *ParentIterator) Done() bool

Done returns true if the iterator has no items left.

func (*ParentIterator) Next

Next returns the next parent link and parent node from the iterator.

type Store

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

Store is a content addressable data store.

func NewStore

func NewStore(store storage.Storage) *Store

NewStore returns a new Store that uses the given storage to read and write content addressable data.

func (*Store) GetNode

func (s *Store) GetNode(ctx context.Context, path datamodel.Path, node datamodel.Node) (datamodel.Node, error)

GetNode returns the node at the given path starting from the given node.

func (*Store) Load

Load returns the node matching the given link and built using the given prototype.

func (*Store) ParentIterator

func (s *Store) ParentIterator(rootLink datamodel.Link) *ParentIterator

ParentIterator returns a new iterator that can be used to iterate through all parents of a root node.

func (*Store) SetNode

func (s *Store) SetNode(ctx context.Context, path datamodel.Path, node datamodel.Node, value datamodel.Node) (datamodel.Node, error)

SetNode sets the node at the given path starting from the given node returning the updated node.

func (*Store) Store

func (s *Store) Store(ctx context.Context, node datamodel.Node) (datamodel.Link, error)

Store writes the given node to the db and returns its link.

func (*Store) Traversal

func (s *Store) Traversal(ctx context.Context) traversal.Progress

Traversal returns a traversal.Progress configured with the default values for this db.

type Transaction

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

Transaction is used to create, read, update, and delete documents.

func NewTransaction

func NewTransaction(ctx context.Context, store *Store, schema *ast.Schema, rootLink datamodel.Link) (*Transaction, error)

NewTransaction creates a new transaction using the given store, schema, and root link.

func (*Transaction) Commit

func (t *Transaction) Commit(ctx context.Context) (datamodel.Link, error)

Commit creates a new root node containing the mutations that were applied during the lifetime of this transaction.

func (*Transaction) CreateDocument

func (t *Transaction) CreateDocument(ctx context.Context, collection string, value map[string]any) (string, error)

CreateDocument creates a document in the given collection using the given value and returns its unique id.

func (*Transaction) DeleteDocument

func (t *Transaction) DeleteDocument(ctx context.Context, collection, id string) error

DeleteDocument deletes the document in the given collection with the given id.

func (*Transaction) DocumentIterator

func (t *Transaction) DocumentIterator(ctx context.Context, collection string) (*DocumentIterator, error)

DocumentIterator returns a new iterator that can be used to iterate through all documents in a collection.

func (*Transaction) PatchDocument

func (t *Transaction) PatchDocument(ctx context.Context, collection, id string, value map[string]any) error

PatchDocument patches the document in the given collection with the given id by applying the operations in the given value.

func (*Transaction) ReadDocument

func (t *Transaction) ReadDocument(ctx context.Context, collection, id string) (datamodel.Node, error)

ReadDocument returns the document in the given collection with the given id.

Jump to

Keyboard shortcuts

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