object

package
v0.0.0-...-f7bad0d Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithExtractor

func WithExtractor[
	I any,
	D encoding.BinaryMarshaler,
	PD sstore.PointerBinaryUnmarshaler[D],
](
	e schema.PathExtractor[D],
) func(*Store[I, D, PD])

WithExtractor is an option to set the extractor.

func WithFlatExtractor

func WithFlatExtractor[
	I any,
	D encoding.BinaryMarshaler,
	PD sstore.PointerBinaryUnmarshaler[D],
](
	e schema.PathExtractor[[]byte],
) func(*Store[I, D, PD])

WithFlatExtractor is an option to set the flat extractor.

func WithId

func WithId[
	I any,
	D encoding.BinaryMarshaler,
	PD sstore.PointerBinaryUnmarshaler[D],
](
	id I,
) func(*Object[I, D])

WithId is an option to set the id of the object.

func WithIdCodec

func WithIdCodec[
	I any,
	D encoding.BinaryMarshaler,
	PD sstore.PointerBinaryUnmarshaler[D],
](
	c codec.Codec[I],
) func(*Store[I, D, PD])

WithIdCodec is an option to set the id codec.

func WithIdFunc

func WithIdFunc[
	I any,
	D encoding.BinaryMarshaler,
	PD sstore.PointerBinaryUnmarshaler[D],
](
	f func(*D) (I, error),
) func(*Store[I, D, PD])

WithIdFunc is an option to set the id function.

func WithIndexer

func WithIndexer[
	I any,
	D encoding.BinaryMarshaler,
	PD sstore.PointerBinaryUnmarshaler[D],
](
	name string,
	idx indexing.Indexer[D],
) func(*Store[I, D, PD])

WithIndexer is an option to add an indexer.

func WithMetadata

func WithMetadata[
	I any,
	D encoding.BinaryMarshaler,
	PD sstore.PointerBinaryUnmarshaler[D],
](
	m map[string]any,
) func(*Object[I, D])

WithMetadata is an option to set the metadata of the object.

func WithMetadataFunc

func WithMetadataFunc[
	I any,
	D encoding.BinaryMarshaler,
	PD sstore.PointerBinaryUnmarshaler[D],
](
	f func(_ []byte, _ *D, _ D, oldU, newU *extutil.Metadata) (*extutil.Metadata, error),
) func(*Store[I, D, PD])

WithMetadataFunc is an option to set the metadata function.

Types

type Iterator

type Iterator[I any, D encoding.BinaryMarshaler] struct {
	// contains filtered or unexported fields
}

Iterator is an iterator that unmarshal id, data and optionally fetch metadata.

func (*Iterator[I, D]) Close

func (it *Iterator[I, D]) Close()

Close closes the iterator.

func (*Iterator[I, D]) FetchMeta

func (it *Iterator[I, D]) FetchMeta(b bool) *Iterator[I, D]

FetchMeta sets if the iterator should fetch metadata.

func (*Iterator[I, D]) Item

func (it *Iterator[I, D]) Item() *badger.Item

Item returns the current item.

func (*Iterator[I, D]) Key

func (it *Iterator[I, D]) Key() []byte

Key returns the current key.

func (*Iterator[I, D]) KeyT

func (it *Iterator[I, D]) KeyT() I

KeyT returns the current key.

func (*Iterator[I, D]) Next

func (it *Iterator[I, D]) Next()

Next moves to the next item.

func (*Iterator[I, D]) Rewind

func (it *Iterator[I, D]) Rewind()

Rewind rewinds the iterator.

func (*Iterator[I, D]) Seek

func (it *Iterator[I, D]) Seek(key []byte)

Seek seeks the key.

func (*Iterator[I, D]) SeekT

func (it *Iterator[I, D]) SeekT(key I)

SeekT seeks the key.

func (*Iterator[I, D]) Valid

func (it *Iterator[I, D]) Valid() bool

Valid returns if the iterator is valid.

func (*Iterator[I, D]) Value

func (it *Iterator[I, D]) Value() (*Object[I, D], error)

Value returns the current value.

type Object

type Object[
	I any,
	D encoding.BinaryMarshaler,
] struct {
	Id       *I             `json:"id,omitempty"`
	Data     D              `json:"data,omitempty"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

Object is a generic object that can be stored in a Store.

type Store

type Store[
	I any,
	D encoding.BinaryMarshaler,
	PD sstore.PointerBinaryUnmarshaler[D],
] struct {
	// contains filtered or unexported fields
}

Store is a generic store for objects.

func New

func New[
	I any,
	D encoding.BinaryMarshaler,
	PD sstore.PointerBinaryUnmarshaler[D],
](
	base badgerutils.BadgerStore,
	opts ...func(*Store[I, D, PD]),
) (*Store[I, D, PD], error)

New creates a new Store.

func (*Store[I, D, PD]) AddIndexer

func (s *Store[I, D, PD]) AddIndexer(name string, idx indexing.Indexer[D]) error

AddIndexer adds an indexer to the store.

func (*Store[I, D, PD]) Delete

func (s *Store[I, D, PD]) Delete(id I) error

Delete deletes the key from the store.

func (*Store[I, D, PD]) Get

func (s *Store[I, D, PD]) Get(id I) (*D, error)

Get gets the object with given id from the store.

func (*Store[I, D, PD]) GetObject

func (s *Store[I, D, PD]) GetObject(id I) (*Object[I, D], error)

GetObject gets the object with given id from the store.

func (*Store[I, D, PD]) Indexer

func (s *Store[I, D, PD]) Indexer(name string) *indexing.Extension[D]

Indexer returns the indexer with given name.

func (*Store[I, D, PD]) NewIterator

func (s *Store[I, D, PD]) NewIterator(opts badger.IteratorOptions) *Iterator[I, D]

NewIterator creates a new iterator over the objects.

func (*Store[I, D, PD]) Prefix

func (s *Store[I, D, PD]) Prefix() []byte

Prefix returns the prefix of the store.

func (*Store[I, D, PD]) Query

func (s *Store[I, D, PD]) Query(q string) (badgerutils.Iterator[*Object[I, D]], error)

Query returns the query for the store.

func (*Store[I, D, PD]) Set

func (s *Store[I, D, PD]) Set(d D, opts ...func(*Object[I, D])) error

Set sets the object with given id to the store.

func (*Store[I, D, PD]) SetObject

func (s *Store[I, D, PD]) SetObject(obj *Object[I, D]) error

SetObject sets the object to the store.

Jump to

Keyboard shortcuts

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