repository

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpNew      = "repository: new ->"
	OpIter     = "repository: iter ->"
	OpFind     = "repository: find ->"
	OpFindIter = "repository: find iter ->"
	OpFindByID = "repository: find by ID ->"
	OpCount    = "repository: count ->"
	OpSave     = "repository: save ->"
	OpRemove   = "repository: remove ->"
	OpIndexes  = "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       = errors.New("could not find entity")
	ErrDuplicateKey         = errors.New("entity duplicate key")
	ErrMissingEntityID      = errors.New("missing entity ID")
	ErrMissingCursor        = errors.New("missing iterator cursor")
	ErrMissingEntityFactory = errors.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
}

Jump to

Keyboard shortcuts

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