manipulate

package module
v1.135.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: Apache-2.0 Imports: 5 Imported by: 42

README

Manipulate

Codacy Badge Codacy Badge

Note: this readme is a work in progress

Package manipulate provides everything needed to perform CRUD operations on an elemental based data model.

The main interface is Manipulator. This interface provides various methods for creation, modification, retrieval and so on.

A Manipulator works with elemental.Identifiable.

The storage engine used by a Manipulator is abstracted. By default manipulate provides implementations for Mongo, ReST HTTP 1and a Memory backed datastore. You can of course implement Your own storage implementation.

There is also a mocking package called maniptest to make it easy to mock any manipulator implementation for unit testing.

Each method of a Manipulator is taking a manipulate.Context as argument. The context is used to pass additional informations like a Filter, or some Parameters.

Example for creating an object

// Create a User from a generated Elemental model.
user := models.NewUser() // always use the initializer to get various default value correctly set.
user.FullName := "Antoine Mercadal"
user.Login := "primalmotion"

// Create Mongo Manipulator.
m := manipmongo.New("127.0.0.1", "test")

// Then create the User.
m.Create(nil, user)

Example for retreving an object

// Create a Context with a filter.
ctx := manipulate.NewContextWithFilter(elemental.NewFilterComposer().
    WithKey("login").Equals("primalmotion").
    Done(),
)

// Retrieve the users matching the filter.
var users models.UserLists
m.RetrieveMany(ctx, &users)

Documentation

Overview

Package manipulate provides everything needed to perform CRUD operations on an https://go.aporeto.io/elemental based data model.

The main interface is Manipulator. This interface provides various methods for creation, modification, retrieval and so on. TransactionalManipulator, which is an extension of the Manipulator add methods to manage transactions, like Commit and Abort.

A Manipulator works with some elemental.Identifiables.

The storage engine used by a Manipulator is abstracted. By default manipulate provides implementations for Rest API over HTTP or websocket, Mongo DB, Memory and a mock Manipulator for unit testing. You can of course create your own implementation.

Each method of a Manipulator is taking a manipulate.Context as argument. The context is used to pass additional informations like a Filter or some Parameters.

Example for creating an object:

// Create a User from a generated Elemental model.
user := models.NewUser()
user.FullName, user.Login := "Antoine Mercadal", "primalmotion"

// Create Mongo Manipulator.
m := manipmongo.NewMongoManipulator([]{"127.0.0.1"}, "test", "db-username", "db-password", "db-authsource", 512)

// Then create the User.
m.Create(nil, user)

Example for retreving an object:

// Create a Context with a filter.
ctx := manipulate.NewContextWithFilter(
    manipulate.NewFilterComposer().WithKey("login").Equals("primalmotion").
    Done())

// Retrieve the users matching the filter.
var users models.UserLists
m.RetrieveMany(ctx, models.UserIdentity, &users)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCannotBuildQueryError

func IsCannotBuildQueryError(err error) bool

IsCannotBuildQueryError returns true if the given error is am ErrCannotBuildQuery.

func IsCannotCommitError

func IsCannotCommitError(err error) bool

IsCannotCommitError returns true if the given error is am ErrCannotCommit.

func IsCannotCommunicateError

func IsCannotCommunicateError(err error) bool

IsCannotCommunicateError returns true if the given error is am ErrCannotCommunicate.

func IsCannotExecuteQueryError

func IsCannotExecuteQueryError(err error) bool

IsCannotExecuteQueryError returns true if the given error is am ErrCannotExecuteQuery.

func IsCannotMarshalError

func IsCannotMarshalError(err error) bool

IsCannotMarshalError returns true if the given error is am ErrCannotMarshal.

func IsCannotUnmarshalError

func IsCannotUnmarshalError(err error) bool

IsCannotUnmarshalError returns true if the given error is am ErrCannotUnmarshal.

func IsConstraintViolationError

func IsConstraintViolationError(err error) bool

IsConstraintViolationError returns true if the given error is am ErrConstraintViolation.

func IsDisconnectedError

func IsDisconnectedError(err error) bool

IsDisconnectedError returns true if the given error is am ErrDisconnected.

func IsLockedError

func IsLockedError(err error) bool

IsLockedError returns true if the given error is am ErrLocked.

func IsMultipleObjectsFoundError

func IsMultipleObjectsFoundError(err error) bool

IsMultipleObjectsFoundError returns true if the given error is am ErrMultipleObjectsFound.

func IsNotImplementedError

func IsNotImplementedError(err error) bool

IsNotImplementedError returns true if the given error is am ErrNotImplemented.

func IsObjectNotFoundError

func IsObjectNotFoundError(err error) bool

IsObjectNotFoundError returns true if the given error is am ErrObjectNotFound.

func IsTLSError

func IsTLSError(err error) bool

IsTLSError returns true if the given error is am ErrTLS.

func IsTooManyRequestsError

func IsTooManyRequestsError(err error) bool

IsTooManyRequestsError returns true if the given error is am ErrTooManyRequests.

func IsTransactionNotFoundError

func IsTransactionNotFoundError(err error) bool

IsTransactionNotFoundError returns true if the given error is am ErrTransactionNotFound.

func Iter

func Iter(
	ctx context.Context,
	m Manipulator,
	mctx Context,
	identifiablesTemplate elemental.Identifiables,
	blockSize int,
) (elemental.Identifiables, error)

Iter is a helper function for IterFunc.

It will simply iterates on the object with identity of the given elemental.Identifiables. Not that this function cannot populate the data in the identifiable parameter. Instead It will return the destination.

Always pass an empty elemental.Identifiables to this function

For more information, please check IterFunc documentation.

Example:

dest, err := Iter(context.Background(), m, mctx, model.ThingsList{}, 100)

func IterFunc

func IterFunc(
	ctx context.Context,
	manipulator Manipulator,
	identifiablesTemplate elemental.Identifiables,
	mctx Context,
	iteratorFunc func(block elemental.Identifiables) error,
	blockSize int,
) error

IterFunc calls RetrieveMany on the given Manipulator, and will retrieve the data by block of the given blockSize.

IterFunc will naturally ends and return when there is no more data to pull.

For each retrieved block, the given func will be called with the current data block. If the function returns an error, the error is returned to the caller of IterFunc and the iteration stops.

The given context will be used if the underlying manipulator honors it. Be careful to NOT pass a filter matching objects then updating the objects to not match anynmore. This would shift pagination and will produce unexpected results. To do so, prefer using manipulate.IterUntilFunc

The given manipulate.Context will be used to retry any failed batch recovery.

The identifiablesTemplate parameter is must be an empty elemental.Identifiables that will be used to hold the data block. It is reset at every iteration. Do not rely on it to be filled once IterFunc is complete.

Finally, if the given blockSize is <= 0, then it will use the default that is 1000.

func IterUntilFunc added in v1.65.0

func IterUntilFunc(
	ctx context.Context,
	manipulator Manipulator,
	identifiablesTemplate elemental.Identifiables,
	mctx Context,
	iteratorFunc func(block elemental.Identifiables) error,
	blockSize int,
) error

IterUntilFunc works as IterFunc but pagination will not increase. It will always retrieve the first page with a size of given blockSize.

The goal of this function is to be used with a filter, then update (or delete) the objects that match until no more are matching.

func NewFiltersFromQueryParameters added in v1.130.0

func NewFiltersFromQueryParameters(parameters elemental.Parameters) (*elemental.Filter, error)

NewFiltersFromQueryParameters returns the filters matching any `q` parameters.

func NewNamespaceFilter added in v1.130.0

func NewNamespaceFilter(namespace string, recursive bool) *elemental.Filter

NewNamespaceFilter returns a manipulate filter used to create the namespace filter.

func NewNamespaceFilterWithCustomProperty added in v1.130.0

func NewNamespaceFilterWithCustomProperty(propertyName string, namespace string, recursive bool) *elemental.Filter

NewNamespaceFilterWithCustomProperty allows to create a namespace filter based on a property that is different from `namespace`.

func NewPropagationFilter added in v1.130.0

func NewPropagationFilter(namespace string) *elemental.Filter

NewPropagationFilter returns additional namespace filter matching objects that are in the namespace ancestors chain and propagate down.

func NewPropagationFilterWithCustomProperty added in v1.130.0

func NewPropagationFilterWithCustomProperty(
	propagationPropName string,
	namespacePropName string,
	namespace string,
	addititionalFiltering *elemental.Filter,
) *elemental.Filter

NewPropagationFilterWithCustomProperty returns additional namespace filter matching objects that are in the namespace ancestors chain and propagate down. The two first properties allows to define the property name to use for propation and namespace. You can also set an additional filter that will be be AND'ed to each subfilters, allowing to create filters like `(namespace == '/parent' and propagate == true and customProp == 'x')`

func Retry deprecated

func Retry(ctx context.Context, manipulateFunc func() error, onRetryFunc func(int, error) error) error

Retry only calls manipulateFunc for backward compatibility.

Deprecated: manipulate.Retry is deprecated. Retry mechanism is now part of Manipulator implementations. You can safely remove this wrapper.

Types

type BufferedManipulator

type BufferedManipulator interface {
	FlushableManipulator
	Manipulator
}

A BufferedManipulator is a Manipulator with a local cache

type Context

type Context interface {
	Count() int
	SetCount(count int)
	Filter() *elemental.Filter
	Finalizer() FinalizerFunc
	Version() int
	TransactionID() TransactionID
	Page() int
	PageSize() int
	After() string
	Limit() int
	Next() string
	SetNext(string)
	Override() bool
	Recursive() bool
	Namespace() string
	Propagated() bool
	Credentials() (string, string)
	Parameters() url.Values
	Parent() elemental.Identifiable
	ExternalTrackingID() string
	ExternalTrackingType() string
	Order() []string
	Context() context.Context
	Derive(...ContextOption) Context
	Fields() []string
	ReadConsistency() ReadConsistency
	WriteConsistency() WriteConsistency
	Messages() []string
	SetMessages([]string)
	ClientIP() string
	RetryFunc() RetryFunc
	RetryRatio() int64

	fmt.Stringer
}

A Context holds all information regarding a particular manipulate operation.

func NewContext

func NewContext(ctx context.Context, options ...ContextOption) Context

NewContext creates a context with the given ContextOption.

type ContextOption

type ContextOption func(Context)

ContextOption represents an option can can be passed to NewContext.

func ContextOptionAfter added in v1.110.0

func ContextOptionAfter(from string, limit int) ContextOption

ContextOptionAfter sets the lazy pagination option of the context.

func ContextOptionClientIP added in v1.54.1

func ContextOptionClientIP(clientIP string) ContextOption

ContextOptionClientIP sets the optional headers for the request.

func ContextOptionCredentials added in v1.54.1

func ContextOptionCredentials(username, password string) ContextOption

ContextOptionCredentials sets user name and password for this context.

func ContextOptionFields

func ContextOptionFields(fields []string) ContextOption

ContextOptionFields sets the list of fields to include in the reply.

func ContextOptionFilter

func ContextOptionFilter(f *elemental.Filter) ContextOption

ContextOptionFilter sets the filter.

func ContextOptionFinalizer

func ContextOptionFinalizer(f FinalizerFunc) ContextOption

ContextOptionFinalizer sets the create finalizer option of the context.

func ContextOptionIdempotencyKey added in v1.112.0

func ContextOptionIdempotencyKey(key string) ContextOption

ContextOptionIdempotencyKey sets a custom idempotency key.

func ContextOptionNamespace

func ContextOptionNamespace(n string) ContextOption

ContextOptionNamespace sets the namespace.

func ContextOptionOpaque added in v1.120.0

func ContextOptionOpaque(o map[string]any) ContextOption

ContextOptionOpaque sets a opaque data. Their interpretation depends on the manipulator implementation.

func ContextOptionOrder

func ContextOptionOrder(orders ...string) ContextOption

ContextOptionOrder sets the ordering option of the context.

func ContextOptionOverride

func ContextOptionOverride(o bool) ContextOption

ContextOptionOverride sets the override option of the context.

func ContextOptionPage

func ContextOptionPage(n, size int) ContextOption

ContextOptionPage sets the pagination option of the context.

func ContextOptionParameters

func ContextOptionParameters(p url.Values) ContextOption

ContextOptionParameters sets the parameters option of the context.

func ContextOptionParent

func ContextOptionParent(i elemental.Identifiable) ContextOption

ContextOptionParent sets the parent option of the context.

func ContextOptionPropagated added in v1.130.0

func ContextOptionPropagated(p bool) ContextOption

ContextOptionPropagated sets the propagated option of the context.

func ContextOptionReadConsistency

func ContextOptionReadConsistency(consistency ReadConsistency) ContextOption

ContextOptionReadConsistency sets the desired read consistency of the request.

func ContextOptionRecursive

func ContextOptionRecursive(r bool) ContextOption

ContextOptionRecursive sets the recursive option of the context.

func ContextOptionRetryFunc added in v1.61.0

func ContextOptionRetryFunc(f RetryFunc) ContextOption

ContextOptionRetryFunc sets the retry function. This function will be called on every communication error, and will be passed the try number and the error. If it itself return an error, retrying will stop and that error will be returned from the manipulator operation.

func ContextOptionRetryRatio added in v1.61.0

func ContextOptionRetryRatio(r int64) ContextOption

ContextOptionRetryRatio sets the retry ratio.

RetryRatio divides the remaining time unitl context deadline to perfrom single retry query down to a minimum defined by manipulator implementations (typically 20s). The default value is 4.

For example if the context has a timeout of 2m, each retry will use a sub context with a timeout of 30s.

func ContextOptionToken added in v1.54.1

func ContextOptionToken(token string) ContextOption

ContextOptionToken sets the token for this request.

func ContextOptionTracking

func ContextOptionTracking(identifier, typ string) ContextOption

ContextOptionTracking sets the opentracing tracking option of the context.

func ContextOptionTransactionID added in v1.65.1

func ContextOptionTransactionID(tid TransactionID) ContextOption

ContextOptionTransactionID sets the parameters option of the context.

func ContextOptionVersion

func ContextOptionVersion(v int) ContextOption

ContextOptionVersion sets the version option of the context.

func ContextOptionWriteConsistency

func ContextOptionWriteConsistency(consistency WriteConsistency) ContextOption

ContextOptionWriteConsistency sets the desired write consistency of the request.

type ErrCannotBuildQuery

type ErrCannotBuildQuery struct{ Err error }

ErrCannotBuildQuery represents query building error.

func NewErrCannotBuildQuery deprecated

func NewErrCannotBuildQuery(message string) ErrCannotBuildQuery

NewErrCannotBuildQuery returns a new ErrCannotBuildQuery.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrCannotBuildQuery) Error

func (e ErrCannotBuildQuery) Error() string

func (ErrCannotBuildQuery) Unwrap added in v1.121.2

func (e ErrCannotBuildQuery) Unwrap() error

Unwrap unwraps the internal error.

type ErrCannotCommit

type ErrCannotCommit struct{ Err error }

ErrCannotCommit represents commit execution error.

func NewErrCannotCommit deprecated

func NewErrCannotCommit(message string) ErrCannotCommit

NewErrCannotCommit returns a new ErrCannotCommit.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrCannotCommit) Error

func (e ErrCannotCommit) Error() string

func (ErrCannotCommit) Unwrap added in v1.121.2

func (e ErrCannotCommit) Unwrap() error

Unwrap unwraps the internal error.

type ErrCannotCommunicate

type ErrCannotCommunicate struct{ Err error }

ErrCannotCommunicate represents a failure in backend communication.

func NewErrCannotCommunicate deprecated

func NewErrCannotCommunicate(message string) ErrCannotCommunicate

NewErrCannotCommunicate returns a new ErrCannotCommunicate.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrCannotCommunicate) Error

func (e ErrCannotCommunicate) Error() string

func (ErrCannotCommunicate) Unwrap added in v1.121.2

func (e ErrCannotCommunicate) Unwrap() error

Unwrap unwraps the internal error.

type ErrCannotExecuteQuery

type ErrCannotExecuteQuery struct{ Err error }

ErrCannotExecuteQuery represents query execution error.

func NewErrCannotExecuteQuery deprecated

func NewErrCannotExecuteQuery(message string) ErrCannotExecuteQuery

NewErrCannotExecuteQuery returns a new ErrCannotExecuteQuery.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrCannotExecuteQuery) Error

func (e ErrCannotExecuteQuery) Error() string

func (ErrCannotExecuteQuery) Unwrap added in v1.121.2

func (e ErrCannotExecuteQuery) Unwrap() error

Unwrap unwraps the internal error.

type ErrCannotMarshal

type ErrCannotMarshal struct{ Err error }

ErrCannotMarshal represents marshaling error.

func NewErrCannotMarshal deprecated

func NewErrCannotMarshal(message string) ErrCannotMarshal

NewErrCannotMarshal returns a new ErrCannotMarshal.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrCannotMarshal) Error

func (e ErrCannotMarshal) Error() string

func (ErrCannotMarshal) Unwrap added in v1.121.2

func (e ErrCannotMarshal) Unwrap() error

Unwrap unwraps the internal error.

type ErrCannotUnmarshal

type ErrCannotUnmarshal struct{ Err error }

ErrCannotUnmarshal represents unmarshaling error.

func NewErrCannotUnmarshal deprecated

func NewErrCannotUnmarshal(message string) ErrCannotUnmarshal

NewErrCannotUnmarshal returns a new ErrCannotUnmarshal.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrCannotUnmarshal) Error

func (e ErrCannotUnmarshal) Error() string

func (ErrCannotUnmarshal) Unwrap added in v1.121.2

func (e ErrCannotUnmarshal) Unwrap() error

Unwrap unwraps the internal error.

type ErrConstraintViolation

type ErrConstraintViolation struct{ Err error }

ErrConstraintViolation represents a failure to find a transaction.

func NewErrConstraintViolation deprecated

func NewErrConstraintViolation(message string) ErrConstraintViolation

NewErrConstraintViolation returns a new ErrConstraintViolation.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrConstraintViolation) Error

func (e ErrConstraintViolation) Error() string

func (ErrConstraintViolation) Unwrap added in v1.121.2

func (e ErrConstraintViolation) Unwrap() error

Unwrap unwraps the internal error.

type ErrDisconnected

type ErrDisconnected struct{ Err error }

ErrDisconnected represents an error due user disconnection.

func NewErrDisconnected deprecated

func NewErrDisconnected(message string) ErrDisconnected

NewErrDisconnected returns a new ErrDisconnected.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrDisconnected) Error

func (e ErrDisconnected) Error() string

func (ErrDisconnected) Unwrap added in v1.121.2

func (e ErrDisconnected) Unwrap() error

Unwrap unwraps the internal error.

type ErrInvalidQuery added in v1.123.0

type ErrInvalidQuery struct {
	// DueToFilter represents whether the query was invalid likely due to the filter supplied by the client.
	DueToFilter bool
	Err         error
}

ErrInvalidQuery represents an error due to an invalid query.

func (ErrInvalidQuery) Error added in v1.123.0

func (err ErrInvalidQuery) Error() string

func (ErrInvalidQuery) Unwrap added in v1.123.0

func (err ErrInvalidQuery) Unwrap() error

Unwrap unwraps the internal error.

type ErrLocked

type ErrLocked struct{ Err error }

ErrLocked represents the error returned when the server api is locked..

func NewErrLocked deprecated

func NewErrLocked(message string) ErrLocked

NewErrLocked returns a new ErrCannotCommunicate.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrLocked) Error

func (e ErrLocked) Error() string

func (ErrLocked) Unwrap added in v1.121.2

func (e ErrLocked) Unwrap() error

Unwrap unwraps the internal error.

type ErrMultipleObjectsFound

type ErrMultipleObjectsFound struct{ Err error }

ErrMultipleObjectsFound represents too many object found error.

func NewErrMultipleObjectsFound deprecated

func NewErrMultipleObjectsFound(message string) ErrMultipleObjectsFound

NewErrMultipleObjectsFound returns a new ErrMultipleObjectsFound.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrMultipleObjectsFound) Error

func (e ErrMultipleObjectsFound) Error() string

func (ErrMultipleObjectsFound) Unwrap added in v1.121.2

func (e ErrMultipleObjectsFound) Unwrap() error

Unwrap unwraps the internal error.

type ErrNotImplemented

type ErrNotImplemented struct{ Err error }

ErrNotImplemented represents a non implemented function.

func NewErrNotImplemented deprecated

func NewErrNotImplemented(message string) ErrNotImplemented

NewErrNotImplemented returns a new ErrNotImplemented.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrNotImplemented) Error

func (e ErrNotImplemented) Error() string

func (ErrNotImplemented) Unwrap added in v1.121.2

func (e ErrNotImplemented) Unwrap() error

Unwrap unwraps the internal error.

type ErrObjectNotFound

type ErrObjectNotFound struct{ Err error }

ErrObjectNotFound represents object not found error.

func NewErrObjectNotFound deprecated

func NewErrObjectNotFound(message string) ErrObjectNotFound

NewErrObjectNotFound returns a new ErrObjectNotFound.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrObjectNotFound) Error

func (e ErrObjectNotFound) Error() string

func (ErrObjectNotFound) Unwrap added in v1.121.2

func (e ErrObjectNotFound) Unwrap() error

Unwrap unwraps the internal error.

type ErrTLS

type ErrTLS struct{ Err error }

ErrTLS represents the error returned when there is a TLS error.

func NewErrTLS deprecated

func NewErrTLS(message string) ErrTLS

NewErrTLS returns a new ErrTLS.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrTLS) Error

func (e ErrTLS) Error() string

func (ErrTLS) Unwrap added in v1.121.2

func (e ErrTLS) Unwrap() error

Unwrap unwraps the internal error.

type ErrTooManyRequests

type ErrTooManyRequests struct{ Err error }

ErrTooManyRequests represents the error returned when the server api is locked.

func NewErrTooManyRequests deprecated

func NewErrTooManyRequests(message string) ErrTooManyRequests

NewErrTooManyRequests returns a new ErrTooManyRequests.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrTooManyRequests) Error

func (e ErrTooManyRequests) Error() string

func (ErrTooManyRequests) Unwrap added in v1.121.2

func (e ErrTooManyRequests) Unwrap() error

Unwrap unwraps the internal error.

type ErrTransactionNotFound

type ErrTransactionNotFound struct{ Err error }

ErrTransactionNotFound represents a failure to find a transaction.

func NewErrTransactionNotFound deprecated

func NewErrTransactionNotFound(message string) ErrTransactionNotFound

NewErrTransactionNotFound returns a new ErrTransactionNotFound.

Deprecated: this method is deprecated and should not be used anymore.

func (ErrTransactionNotFound) Error

func (e ErrTransactionNotFound) Error() string

func (ErrTransactionNotFound) Unwrap added in v1.121.2

func (e ErrTransactionNotFound) Unwrap() error

Unwrap unwraps the internal error.

type FinalizerFunc

type FinalizerFunc func(o elemental.Identifiable) error

A FinalizerFunc is the type of a function that can be used as a creation finalizer. This is only supported by manipulators that generate an ID to let a chance to the user. to now the intended ID before actually creating the object.

type FlushableManipulator

type FlushableManipulator interface {

	// Flush flushes and empties the cache.
	Flush(ctx context.Context) error
}

A FlushableManipulator is a manipulator that can flush its content to somewhere, like a file.

type Manipulator

type Manipulator interface {

	// RetrieveMany retrieves the a list of objects with the given elemental.Identity and put them in the given dest.
	RetrieveMany(mctx Context, dest elemental.Identifiables) error

	// Retrieve retrieves one or multiple elemental.Identifiables.
	// In order to be retrievable, the elemental.Identifiable needs to have their Identifier correctly set.
	Retrieve(mctx Context, object elemental.Identifiable) error

	// Create creates a the given elemental.Identifiables.
	Create(mctx Context, object elemental.Identifiable) error

	// Update updates one or multiple elemental.Identifiables.
	// In order to be updatable, the elemental.Identifiable needs to have their Identifier correctly set.
	Update(mctx Context, object elemental.Identifiable) error

	// Delete deletes one or multiple elemental.Identifiables.
	// In order to be deletable, the elemental.Identifiable needs to have their Identifier correctly set.
	Delete(mctx Context, object elemental.Identifiable) error

	// DeleteMany deletes all objects of with the given identity or
	// all the ones matching the filter in the given context.
	DeleteMany(mctx Context, identity elemental.Identity) error

	// Count returns the number of objects with the given identity.
	Count(mctx Context, identity elemental.Identity) (int, error)
}

Manipulator is the interface of a storage backend.

type ReadConsistency

type ReadConsistency string

ReadConsistency represents the desired consistency of the request. Not all driver may implement this.

const (
	ReadConsistencyDefault   ReadConsistency = "default"
	ReadConsistencyNearest   ReadConsistency = "nearest"
	ReadConsistencyEventual  ReadConsistency = "eventual"
	ReadConsistencyMonotonic ReadConsistency = "monotonic"
	ReadConsistencyStrong    ReadConsistency = "strong"
	ReadConsistencyWeakest   ReadConsistency = "weakest"
)

Various values for Consistency

type RetryFunc added in v1.61.0

type RetryFunc func(RetryInfo) error

A RetryFunc is a function that can be called during an auto retry. The current manipulate.Context is given, a Stringer interface containing, more info about the current request, the error that caused the retry and the try number. If this function returns an error, the retry procedure will be interupted and this error will be returns to the caller of the operation.

type RetryInfo added in v1.61.0

type RetryInfo interface {
	Err() error
	Context() Context
	Try() int
}

A RetryInfo is the interface that can be passed to RetryFunc that will contain retry information. Content will depend on the manipulator implementation.

type SelfTokenManager added in v1.130.0

type SelfTokenManager interface {

	// SetManipulator will be called to inject the manipulator.
	SetManipulator(Manipulator)

	TokenManager
}

A SelfTokenManager is a TokenManager that can use the manipulator it is used with to retrieve a token. Manipulator will call this function passing itself before using any other method of the interface.

type Subscriber

type Subscriber interface {

	// Start connects to the websocket and starts collecting events
	// until the given context is canceled or any non communication error is
	// received. The eventual error will be received in the Errors() channel.
	// If not nil, the given push config will be applied right away.
	Start(context.Context, *elemental.PushConfig)

	// UpdateFilter updates the current push config.
	UpdateFilter(*elemental.PushConfig)

	// Events returns the events channel.
	Events() chan *elemental.Event

	// Errors returns the errors channel.
	Errors() chan error

	// Status returns the status channel.
	Status() chan SubscriberStatus
}

A Subscriber is the interface to control a push event subscription.

type SubscriberStatus

type SubscriberStatus int

SubscriberStatus is the type of a subscriber status.

const (
	SubscriberStatusInitialConnection SubscriberStatus = iota + 1
	SubscriberStatusInitialConnectionFailure
	SubscriberStatusReconnection
	SubscriberStatusReconnectionFailure
	SubscriberStatusDisconnection
	SubscriberStatusFinalDisconnection
	SubscriberStatusTokenRenewal
)

Various values of SubscriberEvent.

type TokenManager

type TokenManager interface {

	// Issues isses a new token.
	Issue(context.Context) (string, error)

	// Run runs the token renewal job and published the new token in the
	// given channel.
	Run(ctx context.Context, tokenCh chan string)
}

A TokenManager issues an renew tokens periodically.

type TransactionID

type TransactionID string

TransactionID is the type used to define a transcation ID of a store

func NewTransactionID

func NewTransactionID() TransactionID

NewTransactionID returns a new transaction ID.

type TransactionalManipulator

type TransactionalManipulator interface {

	// Commit commits the given TransactionID.
	Commit(id TransactionID) error

	// Abort aborts the give TransactionID. It returns true if
	// a transaction has been effectively aborted, otherwise it returns false.
	Abort(id TransactionID) bool

	Manipulator
}

A TransactionalManipulator is a Manipulator that handles transactions.

type WriteConsistency

type WriteConsistency string

WriteConsistency represents the desired consistency of the request. Not all driver may implement this.

const (
	WriteConsistencyDefault   WriteConsistency = "default"
	WriteConsistencyNone      WriteConsistency = "none"
	WriteConsistencyStrong    WriteConsistency = "strong"
	WriteConsistencyStrongest WriteConsistency = "strongest"
)

Various values for Consistency

Directories

Path Synopsis
internal
Package maniphttp provides a ReST backed Manipulator.
Package maniphttp provides a ReST backed Manipulator.
Package manipmemory provides a go-memdb backed Manipulator.
Package manipmemory provides a go-memdb backed Manipulator.
Package manipmongo provides a MongoDB backed TransactionalManipulator.
Package manipmongo provides a MongoDB backed TransactionalManipulator.
internal
Package internal is a generated GoMock package.
Package internal is a generated GoMock package.
Package maniptest contains a Mockable TransactionalManipulator.
Package maniptest contains a Mockable TransactionalManipulator.
Package manipvortex contains a Manipulator that can be used as cache in front of another Manipulator.
Package manipvortex contains a Manipulator that can be used as cache in front of another Manipulator.

Jump to

Keyboard shortcuts

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