repository

package module
v0.0.0-...-734b89f Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

repository

Some generic library code for dealing with basic (CRUD) repositories.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAll

func FindAll[T any, ID comparable](r interface {
	FindAll(consumer func(ID, T) error) error
}) ([]T, error)

Types

type BlobRepository

type BlobRepository[ID comparable] interface {
	Count(ctx context.Context) (int64, error)                 // Count enumerates all saved blobs at calling time. Due to concurrency, this is always only an indicator.
	Delete(ctx context.Context, id ID) error                  // Delete removes the given blob by id. It does not fail if no such ID exists.
	DeleteAll(ctx context.Context) error                      // DeleteAll clears the repository.
	Write(ctx context.Context, id ID) (io.WriteCloser, error) // Write allocates a new blob for the id and commits the written data on close. To stop, cancel the context.
	Read(ctx context.Context, id ID) (io.ReadCloser, error)   // Read opens the blob or returns a NotFoundError. Close to early release resources.
	FindAll(ctx context.Context) (iter.Iterator[ID], error)   // FindAll finds all blob ids.
}

A BlobRepository provides a bunch of methods to manage a set of blobs (binary large objects) identified by unique identifiers and is thread safe. An ID must not be a pointer type. Always use blobs for data you never want to hold in memory.

type CrudRepository

type CrudRepository[T any, ID comparable] interface {
	Count() (int64, error)                        // Count enumerates all saved entities at calling time.
	DeleteByID(id ID) error                       // DeleteByID remove the given entity. It does not fail if no such ID exists.
	DeleteAll() error                             // DeleteAll clears the repository.
	Save(id ID, entity T) error                   // Save overwrites the entity identified by its ID. It does not fail whether entity already exists.
	SaveAll(producer func() (ID, T, error)) error // SaveAll stores all entities until the first error occurs. Returning an io.EOF will finish processing.
	FindByID(id ID) (T, error)                    // FindByID returns either T or EntityNotFoundError.
	FindAll(consumer func(ID, T) error) error     // FindAll invokes the callback for each entity. The order is unspecified.
}

A CrudRepository provides a bunch of methods to manage a set of entities identified by unique identifiers and is thread safe. The ownership of any returned Entity instance is handed over to the callee and never reused internally. This is quite inefficient but always thread safe.

type EntityNotFoundError

type EntityNotFoundError struct {
	ID any
}

func (EntityNotFoundError) Error

func (e EntityNotFoundError) Error() string

func (EntityNotFoundError) GetID

func (e EntityNotFoundError) GetID() any

func (EntityNotFoundError) NotFound

func (e EntityNotFoundError) NotFound() bool

Directories

Path Synopsis
internal
Package iter provides a generic Iterator pattern, which is reduced to a minimum.
Package iter provides a generic Iterator pattern, which is reduced to a minimum.

Jump to

Keyboard shortcuts

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