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.
Click to show internal directories.
Click to hide internal directories.