store

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrEmptyKey      = errors.New("empty key")
	ErrSerialize     = errors.New("couldn't serialize object")
	ErrDeserialize   = errors.New("couldn't deserialize data")
	ErrInvalidOption = errors.New("invalid option")
	ErrInvalidFilter = errors.New("invalid filter")
)

Functions

This section is empty.

Types

type BaseKeyValueMap

type BaseKeyValueMap interface {
	GetOne(ctx context.Context, key string) (string, error)
	GetMany(ctx context.Context, keys []string) (map[string]string, error)
	GetAll(ctx context.Context) (map[string]string, error)
	SetOne(ctx context.Context, key, value string) error
	SetMany(ctx context.Context, items map[string]string) error
	UpdateOne(ctx context.Context, key string, update func(string, *string) (*string, error)) error
	UpdateMany(ctx context.Context, keys []string, update func(string, *string) (*string, error)) error
	Delete(ctx context.Context, keys ...string) error
}

type BaseKeyValueStore

type BaseKeyValueStore[T any] interface {
	GetOne(ctx context.Context, key string) (*T, error)
	GetMany(ctx context.Context, keys []string) (map[string]*T, error)
	GetAll(ctx context.Context) (map[string]*T, error)
	SetOne(ctx context.Context, key string, value *T) error
	SetMany(ctx context.Context, items map[string]*T) error
	UpdateOne(ctx context.Context, key string, update func(string, *T) (*T, error)) error
	UpdateMany(ctx context.Context, keys []string, update func(string, *T) (*T, error)) error
	Delete(ctx context.Context, keys ...string) error
}

type ErrorMap

type ErrorMap struct {
	ErrNotFound      error
	ErrEmptyKey      error
	ErrSerialize     error
	ErrDeserialize   error
	ErrInvalidOption error
	ErrInvalidFilter error
}

func (*ErrorMap) InitDefaultErrors

func (e *ErrorMap) InitDefaultErrors()

type ErrorMapSetter

type ErrorMapSetter interface {
	SetErrorMap(ErrorMap)
}

type FilterSpec

type FilterSpec struct {
	Where *WhereClause
	All   []*FilterSpec
	Any   []*FilterSpec
}

func All

func All(filters ...*FilterSpec) *FilterSpec

func Any

func Any(filters ...*FilterSpec) *FilterSpec

func Where

func Where(fieldName string, op string, value any) *FilterSpec

type KeyValue

type KeyValue[T any] interface {
	BaseKeyValueStore[T]
	Lister[T]
	ErrorMapSetter
	Resetter
}

type KeyValueMap

type KeyValueMap interface {
	BaseKeyValueMap
	ErrorMapSetter
	Resetter
}

type Lister

type Lister[T any] interface {
	List(ctx context.Context, opts ...*Options) ([]*T, error)
}

type Options

type Options struct {
	Filter  *FilterSpec
	OrderBy *OrderBySpec
	Limit   int
	Offset  int
}

func Filter

func Filter(spec *FilterSpec) *Options

func Limit

func Limit(n int) *Options

func Offset

func Offset(n int) *Options

func Order

func Order(order *OrderBySpec) *Options

func Paginate

func Paginate(limit, offset int) *Options

type OrderBySpec

type OrderBySpec struct {
	Field      string
	Descending bool
}

func By

func By(field string) *OrderBySpec

func (*OrderBySpec) Asc

func (o *OrderBySpec) Asc() *OrderBySpec

func (*OrderBySpec) Desc

func (o *OrderBySpec) Desc() *OrderBySpec

type Resetter

type Resetter interface {
	Reset(ctx context.Context) error
}

type Serializer

type Serializer[T any] interface {
	Serialize(*T) (string, error)
	Deserialize(string) (*T, error)
}

type WhereClause

type WhereClause struct {
	Field string
	Op    string
	Value any
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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