crud

package
v0.104.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ErrAlreadyExists errorutil.Error = "err-already-exists"
	ErrNotFound      errorutil.Error = "err-not-found"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AllDeleter added in v0.80.0

type AllDeleter interface {
	// DeleteAll will erase all entity from the resource that has <V> type
	DeleteAll(context.Context) error
}

type AllFinder added in v0.80.0

type AllFinder[Entity any] interface {
	// FindAll will return all entity that has <V> type
	FindAll(context.Context) iterators.Iterator[Entity]
}

type ByIDDeleter added in v0.80.0

type ByIDDeleter[ID any] interface {
	// DeleteByID will remove a <V> type entity from the repository by a given ID
	DeleteByID(ctx context.Context, id ID) error
}

type ByIDFinder added in v0.80.0

type ByIDFinder[Entity, ID any] interface {
	// FindByID will link an entity that is found in the resource to the received ptr,
	// and report back if it succeeded finding the entity in the resource.
	// It also reports if there was an unexpected exception during the execution.
	// It was an intentional decision to not use error to represent "not found" case,
	// but tell explicitly this information in the form of return bool value.
	FindByID(ctx context.Context, id ID) (ent Entity, found bool, err error)
}

type Creator

type Creator[Entity any] interface {
	// Create takes a ptr to a entity<V> and store it into the resource.
	// It also updates the entity<V> ext:"ID" field with the associated uniq resource id.
	// The reason behind this links the id and not returning the id is that,
	// in most case the Create error value is the only thing that is checked for errors,
	// and introducing an extra value also introduce boiler plates in the handling.
	Create(ctx context.Context, ptr *Entity) error
}

type Deleter

type Deleter[ID any] interface {
	ByIDDeleter[ID]
	AllDeleter
}

Deleter request to destroy a business entity in the Resource that implement it's test.

type Finder

type Finder[Entity, ID any] interface {
	ByIDFinder[Entity, ID]
	AllFinder[Entity]
}

type Purger

type Purger interface {
	// Purge will completely wipe all state from the given resource.
	// It is meant to be used in testing during clean-ahead arrangements.
	Purge(context.Context) error
}

Purger supplies functionality to purge a resource completely. On high level this looks similar to what Deleter do, but in case of an event logged resource, this will purge all the events. After a purge, it is not expected to have anything in the repository. It is heavily discouraged to use Purge for domain interactions.

type Query added in v0.92.0

type Query[Entity any] interface {
	Query(context.Context) iterators.Iterator[Entity]
}

type Updater

type Updater[Entity any] interface {
	// Update will takes a ptr that points to an entity
	// and update the corresponding stored entity with the received entity field values
	Update(ctx context.Context, ptr *Entity) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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