model

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("model not found")

ErrNotFound is returned by repositories when a model cannot be found.

Functions

This section is empty.

Types

type ID

type ID interface {
	comparable
	fmt.Stringer
}

type Model

type Model[T ID] interface {
	ModelID() T
}

Model is an entity with a unique, comparable identifier.

type Repository

type Repository[M Model[IDT], IDT ID] interface {
	// Save saves the given model to the database.
	Save(ctx context.Context, a M) error

	// Fetch fetches the model with the given id from the database. If no model
	// with the given id can be found, an error that unwraps to ErrNotFound
	// should be returned.
	Fetch(ctx context.Context, id IDT) (M, error)

	// Use first fetches the model from the database, then passes the model to
	// the provided function fn and finally saves the model back to the database.
	Use(ctx context.Context, id IDT, fn func(M) error) error

	// Delete deletes the given model from the database.
	Delete(ctx context.Context, a M) error
}

Repository is a generic type that can be used to define repositories for any kind of model.

aggregate.TypedRepository extends this interface.

Jump to

Keyboard shortcuts

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