storage

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket[T comparable] struct {
	// contains filtered or unexported fields
}

Bucket is a generic container for a collection of items. The type of the items is generic, denoted by T. It is thread-safe. Each item gets a unique integer ID. It contains many indexes, each of which maps the 's key to the value's ID. When an item is added to the bucket, it is indexed by the indexes given by the user as a map It supports the following operations: - Add(T) error: adds an item to the bucket. - All() []T: gets all items from the bucket. - One(*Query) (T, error): retrievs the single item from the bucket that matches the provided query. - Some(*Query) []T: retrieves all items from the bucket that match the provided query. - Remove(*Query) error: removes the single item from the bucket that matches the provided query. - Clear(): removes all items and recorded indices from the bucket. - WithIndex(name, Index, Derivator) *Bucket: adds an index to the bucket. - Finalize() *Bucket: finalizes the bucket as ready for use.

func NewBucket

func NewBucket[T comparable]() *Bucket[T]

NewBucket creates a new Bucket.

func (*Bucket[T]) Add

func (b *Bucket[T]) Add(item T) error

add adds the given item to the bucket. It returns an error if the item is nil. It returns an error if the item is already in the bucket.

func (*Bucket[T]) All

func (b *Bucket[T]) All() []T

Retrieve all items from the bucket. It returns an empty slice if the bucket is empty.

func (*Bucket[T]) Clear

func (b *Bucket[T]) Clear()

Clear clears the bucket.

func (*Bucket[T]) Finalize

func (b *Bucket[T]) Finalize() *Bucket[T]

Finalize finalizes the bucket as ready for use.

func (*Bucket[T]) One

func (b *Bucket[T]) One(query *Query) (T, error)

Retrieve the single item from the bucket that matches the given filters. It returns an error if no filters are given. It returns an error if no item matches the given filters. It returns an error if more than one item matches the given filters.

func (*Bucket[T]) Remove

func (b *Bucket[T]) Remove(query *Query) error

remove removes the given item from the bucket. It returns an error if the item doesn't exist. It returns an error if the item is in the bucket more than once.

func (*Bucket[T]) Some

func (b *Bucket[T]) Some(query *Query) []T

Retrieve all items from the bucket that match the given filters. With filters, it returns all items that match the given filters. It returns an empty slice if no filters are given. It returns an empty slice if no items match the given filters.

func (*Bucket[T]) WithIndex

func (b *Bucket[T]) WithIndex(name string, index core.Index, derivator core.Derivator) *Bucket[T]

WithIndex adds an index to the bucket.

type Query

type Query struct {
	Indices internal.Indices
}

func NewQuery

func NewQuery() *Query

func (*Query) And

func (q *Query) And(name string, value interface{}) *Query

func (*Query) Finalize

func (q *Query) Finalize() (internal.Indices, error)

func (*Query) Where

func (q *Query) Where(name string, value interface{}) *Query

Jump to

Keyboard shortcuts

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