rec

package
v0.0.0-...-50414e9 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithSequenceAsIdFunc

func WithSequenceAsIdFunc[
	I constraints.Integer,
	T any,
](
	seq *badger.Sequence,
) func(_ *T) (I, error)

WithSequenceAsIdFunc is an option to set the id function to use a sequence.

Types

type Doc

type Doc[I comparable] map[string]any

Doc is a Record type that is schemaless. This type is serialized entirely in msgpack format so MsgpackPathExtractor can be used as flat extractor in record store to speed up queries without the need of deserializing the whole document.

func (Doc[I]) GetId

func (doc Doc[I]) GetId() I

GetId implements the Record interface.

func (Doc[I]) MarshalBinary

func (doc Doc[I]) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Doc[I]) SetId

func (doc Doc[I]) SetId(id I)

SetId implements the Record interface.

func (*Doc[I]) UnmarshalBinary

func (doc *Doc[I]) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type Instance

type Instance[
	I comparable,
	T any,
	PT Record[I, T],
] struct {
	// contains filtered or unexported fields
}

Instance is an instance of the Store.

func (*Instance[I, T, PT]) Delete

func (s *Instance[I, T, PT]) Delete(id I) error

Delete implements the badgerutils.StoreInstance interface.

func (*Instance[I, T, PT]) Get

func (s *Instance[I, T, PT]) Get(id I) (*T, error)

Get implements the badgerutils.StoreInstance interface.

func (*Instance[I, T, PT]) NewIterator

func (s *Instance[I, T, PT]) NewIterator(opts badger.IteratorOptions) *Iterator[I, T]

NewIterator implements the badgerutils.StoreInstance interface.

func (*Instance[I, T, PT]) Query

func (s *Instance[I, T, PT]) Query(q string) (badgerutils.Iterator[I, *T], error)

Query returns the query for the store.

func (*Instance[I, T, PT]) Set

func (s *Instance[I, T, PT]) Set(v *T, opts ...any) error

Set implements the badgerutils.StoreInstance interface.

type Iterator

type Iterator[I comparable, T any] struct {
	// contains filtered or unexported fields
}

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

func (*Iterator[I, T]) Close

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

Close closes the iterator.

func (*Iterator[I, T]) Item

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

Item returns the current item.

func (*Iterator[I, T]) Key

func (it *Iterator[I, T]) Key() (k I, err error)

Key returns the current key.

func (*Iterator[I, T]) Next

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

Next moves to the next item.

func (*Iterator[I, T]) Rewind

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

Rewind rewinds the iterator.

func (*Iterator[I, T]) Seek

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

Seek seeks the key.

func (*Iterator[I, T]) SeekT

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

SeekT seeks the key.

func (*Iterator[I, T]) Valid

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

Valid returns if the iterator is valid.

func (*Iterator[I, T]) Value

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

Value returns the current value.

type Object

type Object[I comparable, D any] 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 as a Record.

func NewObject

func NewObject[I comparable, D any](data D) *Object[I, D]

NewObject creates a new object with the given data.

func NewObjectWithId

func NewObjectWithId[I comparable, D any](id I, data D) *Object[I, D]

NewObjectWithId creates a new object with the given data and id.

func (Object[I, D]) GetId

func (obj Object[I, D]) GetId() I

GetId implements the Record interface.

func (Object[I, D]) MarshalBinary

func (obj Object[I, D]) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Object[I, D]) SetId

func (obj *Object[I, D]) SetId(id I)

SetId implements the Record interface.

func (*Object[I, D]) UnmarshalBinary

func (obj *Object[I, D]) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type Record

type Record[I comparable, T any] interface {
	*T
	GetId() I
	SetId(I)
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

Record is a model for something that is serializable and has an unique id assigned to it. One thing to consider here is that the id is serialized as key in the store so there's no need to serialize it as part of the value.

type Store

type Store[
	I comparable,
	T any,
	PT Record[I, T],
] struct {
	// contains filtered or unexported fields
}

Store is a generic store for entities.

func New

func New[
	I comparable,
	T any,
	PT Record[I, T],
](
	base badgerutils.Instantiator[badgerutils.BadgerStore],
) *Store[I, T, PT]

New creates a new Store.

func (*Store[I, T, PT]) IdCodec

func (s *Store[I, T, PT]) IdCodec() codec.Codec[I]

IdCodec returns the id codec.

func (*Store[I, T, PT]) Indexer

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

Indexer returns the indexer with given name.

func (*Store[I, T, PT]) Instantiate

func (s *Store[I, T, PT]) Instantiate(txn *badger.Txn) *Instance[I, T, PT]

Instantiate implements the badgerutils.Instantiator interface.

func (*Store[I, T, PT]) Prefix

func (s *Store[I, T, PT]) Prefix() []byte

Prefix returns the prefix of the store.

func (*Store[I, T, PT]) WithExtension

func (s *Store[I, T, PT]) WithExtension(name string, ext extstore.Extension[I, T]) *Store[I, T, PT]

WithExtension adds an extension to the store.

func (*Store[I, T, PT]) WithExtractor

func (s *Store[I, T, PT]) WithExtractor(e schema.PathExtractor[*T]) *Store[I, T, PT]

WithExtractor is an option to set the extractor.

func (*Store[I, T, PT]) WithFlatExtractor

func (s *Store[I, T, PT]) WithFlatExtractor(e schema.PathExtractor[[]byte]) *Store[I, T, PT]

WithFlatExtractor is an option to set the flat extractor.

func (*Store[I, T, PT]) WithIdCodec

func (s *Store[I, T, PT]) WithIdCodec(c codec.Codec[I]) *Store[I, T, PT]

WithIdCodec is an option to set the id codec.

func (*Store[I, T, PT]) WithIdFunc

func (s *Store[I, T, PT]) WithIdFunc(f func(*T) (I, error)) *Store[I, T, PT]

WithIdFunc is an option to set the id function.

func (*Store[I, T, PT]) WithIndexer

func (s *Store[I, T, PT]) WithIndexer(name string, idx indexing.Indexer[T]) *Store[I, T, PT]

WithIndexer adds an indexer to the store.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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