resource

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package resource contains utilities for performing low-level manipulations of projection resource versions.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = errors.New("the handler does not support this operation")

ErrNotSupported indicates that the handler does not support a low-level resource operation.

Functions

func DeleteResource

func DeleteResource(
	ctx context.Context,
	h dogma.ProjectionMessageHandler,
	r []byte,
) (bool error)

DeleteResource removes all information about the resource r from the handler's data store.

For some handler implementations, this is *likely* to be an equivalent operation to h.CloseResource(), however handler implementations are not *required* to remove data about a resource when it is closed.

Furthermore, the result of deleting a resource should be that the handler will behave as though it had never had such a resource, whereas the behavior of a projection when using a closed resource is undefined.

It returns ErrNotSupported if the handler does not support deleting resources.

func StoreVersion

func StoreVersion(
	ctx context.Context,
	h dogma.ProjectionMessageHandler,
	r, v []byte,
) error

StoreVersion unconditionally sets the version of the resource r to v.

Care should be taken using this function, as it bypasses the optimistic-concurrency checks normally present when updating a resource version. It's almost always better to use UpdateVersion() instead.

It returns ErrNotSupported if the handler does not support storing resource versions outside of when an event is handled.

func UpdateVersion

func UpdateVersion(
	ctx context.Context,
	h dogma.ProjectionMessageHandler,
	r, c, n []byte,
) (ok bool, err error)

UpdateVersion updates the version of the resource r to n if the current version is c.

It returns false if c is not the current version.

It returns ErrNotSupported if the handler does not support storing resource versions outside of when an event is handled.

Types

type Repository added in v0.6.4

type Repository interface {
	// ResourceVersion returns the version of the resource r.
	ResourceVersion(ctx context.Context, r []byte) ([]byte, error)

	// StoreResourceVersion sets the version of the resource r to v without
	// checking the current version.
	StoreResourceVersion(ctx context.Context, r, v []byte) error

	// UpdateResourceVersion updates the version of the resource r to n.
	//
	// If c is not the current version of r, it returns false and no update occurs.
	UpdateResourceVersion(ctx context.Context, r, c, n []byte) (bool, error)

	// DeleteResource removes all information about the resource r.
	DeleteResource(ctx context.Context, r []byte) error
}

Repository is an interface for low-level management of resource versions.

This interface is intended to aid implementing higher-order projections on top of the projection types provided by this module.

For general management of persisted resource versions the functions in this package should be used instead.

type RepositoryAware added in v0.6.4

type RepositoryAware interface {
	// ResourceRepository returns a repository that can be used to manipulate
	// the handler's resource versions.
	ResourceRepository() Repository
}

RepositoryAware is an interface for projection message handlers that can provide a resource repository for low-level manipulation of resource versions.

Jump to

Keyboard shortcuts

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