store

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package store provides a generic interface to zettel stores.

Package store provides a generic interface to zettel stores.

Package store provides a generic interface to zettel stores.

Index

Constants

This section is empty.

Variables

View Source
var ErrStopped = errors.New("Store is stopped")

ErrStopped is returned if calling methods on a store that was not started.

Functions

func ApplySorter

func ApplySorter(metaList []*domain.Meta, s *Sorter) []*domain.Meta

ApplySorter applies the given sorter to the slide of meta data.

Types

type ErrInvalidID

type ErrInvalidID struct{ ID domain.ZettelID }

ErrInvalidID is returned if the zettel ID is not appropriate for the store operation.

func (*ErrInvalidID) Error

func (err *ErrInvalidID) Error() string

type ErrUnknownID

type ErrUnknownID struct{ ID domain.ZettelID }

ErrUnknownID is returned if the zettel ID is unknown to the store.

func (*ErrUnknownID) Error

func (err *ErrUnknownID) Error() string

type Filter

type Filter struct {
	Expr   FilterExpr
	Negate bool
}

Filter specifies a mechanism for selecting zettel.

type FilterExpr

type FilterExpr map[string][]string // map of keys to or-ed values

FilterExpr is the encoding of a search filter.

type FilterFunc

type FilterFunc func(*domain.Meta) bool

FilterFunc is a predicate to check if given meta must be selected.

func CreateFilterFunc

func CreateFilterFunc(filter *Filter) FilterFunc

CreateFilterFunc calculates a filter func based on the given filter.

type Sorter

type Sorter struct {
	Order  string // Name of meta key. None given: use "id". If key starts with "-" use descending order.
	Offset int    // <= 0: no offset
	Limit  int    // <= 0: no limit
}

Sorter specifies ordering and limiting a sequnce of meta data.

type Store

type Store interface {
	// SetParentStore is called when the store is part of a bigger store.
	SetParentStore(parent Store)

	// Location returns some information where the store is located.
	// Format is dependent of the store.
	Location() string

	// Start the store. Now all other functions of the store are allowed.
	// Starting an already started store is not allowed.
	Start(ctx context.Context) error

	// Stop the started store. Now only the Start() function is allowed.
	Stop(ctx context.Context) error

	// RegisterChangeObserver registers an observer that will be notified
	// if a zettel was found to be changed. If the id is empty, all zettel are
	// possibly changed.
	RegisterChangeObserver(func(domain.ZettelID))

	// GetZettel retrieves a specific zettel.
	GetZettel(ctx context.Context, id domain.ZettelID) (domain.Zettel, error)

	// GetMeta retrieves just the meta data of a specific zettel.
	GetMeta(ctx context.Context, id domain.ZettelID) (*domain.Meta, error)

	// SelectMeta returns all zettel meta data that match the selection criteria.
	// TODO: more docs
	SelectMeta(ctx context.Context, f *Filter, s *Sorter) ([]*domain.Meta, error)

	// SetZettel updates an existing zettel or creates a new one.
	// It the zettel contains a valid ID, an update operation is assumed,
	// otherwise the store must assign a new ID for the zettel. In this case, the
	// meta data of the zettel will contain the updated ID. The caller is
	// potentially allowed to assign an ID itself, but at own risk.
	SetZettel(ctx context.Context, zettel domain.Zettel) error

	// DeleteZettel removes the zettel from the store.
	DeleteZettel(ctx context.Context, id domain.ZettelID) error

	// Rename changes the current ID to a new ID.
	RenameZettel(ctx context.Context, curID, newID domain.ZettelID) error

	// Reload clears all caches, reloads all internal data to reflect changes
	// that were possibly undetected.
	Reload(ctx context.Context) error
}

Store is implemented by all Zettel stores.

Directories

Path Synopsis
Package chainstore provides a union of connected zettel stores of different type.
Package chainstore provides a union of connected zettel stores of different type.
Package filestore provides a file based zettel store.
Package filestore provides a file based zettel store.
directory
Package directory manages the directory part of a file store.
Package directory manages the directory part of a file store.
Package gostore stores zettel inside the executable.
Package gostore stores zettel inside the executable.
Package stock allows to get zettel without reading it from the store.
Package stock allows to get zettel without reading it from the store.

Jump to

Keyboard shortcuts

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