storages

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoEntity = errors.New("no such entity")
)

Functions

This section is empty.

Types

type BundleEngine

type BundleEngine interface {
	NewStorage(bundle *pathbuilder.Bundle) (BundleStorage, error)
}

BundleEngine is a function that initializes and returns a new BundleStorage

func NewBundleEngine

func NewBundleEngine(path string) BundleEngine

NewBundleEngine creates a new BundleEngine backed by the disk at the provided path. If path is the empty string, return a memory-backed engine instead.

type BundleStorage

type BundleStorage interface {
	io.Closer

	// Add adds a new entity with the given URI (and optional path information)
	// to this bundle.
	//
	// Calls to add for a specific bundle storage are serialized.
	Add(uri wisski.URI, path []wisski.URI, triples []wisski.Triple) error

	// AddFieldValue adds a value to the given field for the entity with the given uri.
	//
	// Concurrent calls to distinct fields may take place, however within each field calls are always syncronized.
	//
	// A non-existing parent should return ErrNoEntity.
	AddFieldValue(uri wisski.URI, field string, value any, path []wisski.URI, triples []wisski.Triple) error

	// RegisterChildStorage register the given storage as a BundleStorage for the child bundle.
	// The Storage should delete the reference to the child storage when it is closed.
	RegisterChildStorage(bundle string, storage BundleStorage) error

	// AddChild adds a child entity of the given bundle to the given entity.
	//
	// Multiple concurrent calls to AddChild may take place, but every concurrent call will be for a different bundle.
	//
	// A non-existing parent should return ErrNoEntity.
	AddChild(parent wisski.URI, bundle string, child wisski.URI) error

	// Finalize is called to signal to this storage that no more write operations will take place.
	Finalize() error

	// Get returns an iterator that iterates over the url of every entity in this bundle, along with their parent URIs.
	// The iterator is guaranteed to iterate in some consistent order, but no further guarantees beyond that.
	//
	// parentPathIndex returns the index of the parent uri in child paths.
	Get(parentPathIndex int) iterator.Iterator[URIWithParent]

	// Count counts the number of entities in this storage.
	Count() (int64, error)

	// Load loads an entity with the given URI from this storage.
	// A non-existing entity should return err = ErrNoEntity.
	Load(uri wisski.URI) (wisski.Entity, error)
}

BundleStorage is responsible for storing entities for a single bundle

type Disk

type Disk struct {
	DB *leveldb.DB
	// contains filtered or unexported fields
}

Disk represents a disk-backed storage

func (*Disk) Add

func (ds *Disk) Add(uri wisski.URI, path []wisski.URI, triples []wisski.Triple) error

Add adds an entity to this BundleSlice

func (*Disk) AddChild

func (ds *Disk) AddChild(parent wisski.URI, bundle string, child wisski.URI) error

func (*Disk) AddFieldValue

func (ds *Disk) AddFieldValue(uri wisski.URI, field string, value any, path []wisski.URI, triples []wisski.Triple) error

func (*Disk) Close

func (ds *Disk) Close() error

func (*Disk) Count

func (ds *Disk) Count() (int64, error)

func (*Disk) Finalize

func (ds *Disk) Finalize() error

func (*Disk) Get

func (ds *Disk) Get(parentPathIndex int) iterator.Iterator[URIWithParent]

func (*Disk) Load

func (ds *Disk) Load(uri wisski.URI) (entity wisski.Entity, err error)

func (*Disk) RegisterChildStorage

func (ds *Disk) RegisterChildStorage(bundle string, storage BundleStorage) error

type DiskEngine

type DiskEngine struct {
	Path string
}

func (DiskEngine) NewStorage

func (de DiskEngine) NewStorage(bundle *pathbuilder.Bundle) (BundleStorage, error)

type Memory

type Memory struct {
	Entities []wisski.Entity
	// contains filtered or unexported fields
}

Memory implements an in-memory bundle storage

func (*Memory) Add

func (bs *Memory) Add(uri wisski.URI, path []wisski.URI, triples []wisski.Triple) error

Add adds an entity to this BundleSlice

func (*Memory) AddChild

func (bs *Memory) AddChild(parent wisski.URI, bundle string, child wisski.URI) error

func (*Memory) AddFieldValue

func (bs *Memory) AddFieldValue(uri wisski.URI, field string, value any, path []wisski.URI, triples []wisski.Triple) error

func (*Memory) Close

func (bs *Memory) Close() error

func (*Memory) Count

func (bs *Memory) Count() (int64, error)

func (*Memory) Finalize

func (bs *Memory) Finalize() error

func (*Memory) Get

func (bs *Memory) Get(parentPathIndex int) iterator.Iterator[URIWithParent]

func (*Memory) Load

func (bs *Memory) Load(uri wisski.URI) (entity wisski.Entity, err error)

func (*Memory) RegisterChildStorage

func (bs *Memory) RegisterChildStorage(bundle string, storage BundleStorage) error

type MemoryEngine

type MemoryEngine struct{}

func (MemoryEngine) NewStorage

func (MemoryEngine) NewStorage(bundle *pathbuilder.Bundle) (BundleStorage, error)

type URIWithParent

type URIWithParent struct {
	URI    wisski.URI
	Parent wisski.URI
}

URIWithParent represents a URI along with it's parent

Jump to

Keyboard shortcuts

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