Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
Click to show internal directories.
Click to hide internal directories.