repository

package
v2.0.0-alpha3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpNew      errs.Op = "repository: new"
	OpIter     errs.Op = "repository: iter"
	OpFind     errs.Op = "repository: find"
	OpFindIter errs.Op = "repository: find iter"
	OpFindByID errs.Op = "repository: find by ID"
	OpCount    errs.Op = "repository: count"
	OpSave     errs.Op = "repository: save"
	OpRemove   errs.Op = "repository: remove"
	OpIndexes  errs.Op = "repository: indexes"

	ErrMsgDecode    = "failed to decode entity due to error: %w"
	ErrMsgAfterFind = "failed after find callback due to error: %w"
)

Variables

View Source
var (
	ErrEntityNotFound       = errs.New("could not find entity")
	ErrDuplicateKey         = errs.New("entity duplicate key")
	ErrMissingEntityID      = errs.New("missing entity ID")
	ErrMissingCursor        = errs.New("missing iterator cursor")
	ErrMissingEntityFactory = errs.New("missing entity factory")
)

Functions

This section is empty.

Types

type Criteria

type Criteria struct {
	Filter any
	Sort   any
	Index  *int64
	Size   *int64
}

func (*Criteria) SetIndex

func (c *Criteria) SetIndex(index int64) *Criteria

func (*Criteria) SetSize

func (c *Criteria) SetSize(size int64) *Criteria

type Cursor

type Cursor interface {
	Next(ctx context.Context) bool
	Decode(val any) error
	Close(ctx context.Context) error
	Err() error
}

type Entity

type Entity interface {
	EntityID() uuid.UUID
}

type EntityFactory

type EntityFactory[T Entity] interface {
	NewEntity() T
}

func Factory

func Factory[T Entity]() EntityFactory[T]

type EntityFactoryFunc

type EntityFactoryFunc[T Entity] func() T

func (EntityFactoryFunc[T]) NewEntity

func (f EntityFactoryFunc[T]) NewEntity() T

type Iter

type Iter[T Entity] interface {
	Next(ctx context.Context) bool
	Entity() T
	Close(ctx context.Context) error
}

type Iterator

type Iterator[T Entity] struct {
	Cursor    Cursor
	Factory   EntityFactory[T]
	AfterFind func(entity T) error
	// contains filtered or unexported fields
}

func (*Iterator[T]) Close

func (i *Iterator[T]) Close(ctx context.Context) (err error)

func (*Iterator[T]) Entity

func (i *Iterator[T]) Entity() T

func (*Iterator[T]) Next

func (i *Iterator[T]) Next(ctx context.Context) bool

type ReadRepository

type ReadRepository[T Entity] interface {
	Count(ctx context.Context, filter any) (int64, error)
	Find(ctx context.Context, criteria *Criteria) ([]T, error)
	FindIter(ctx context.Context, criteria *Criteria) (Iter[T], error)
	FindByID(ctx context.Context, id uuid.UUID) (T, error)
}

type ReadWriteRepository

type ReadWriteRepository[T Entity] interface {
	ReadRepository[T]
	WriteRepository[T]
}

type WriteRepository

type WriteRepository[T Entity] interface {
	Save(ctx context.Context, entity T) error
	Remove(ctx context.Context, id uuid.UUID) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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