cqrs-core-0.10.0: Command-Query Responsibility Segregation

Safe HaskellNone
LanguageHaskell2010

Data.CQRS.Command

Description

Module to import for the Command side of the application.

Synopsis

Documentation

type AggregateAction a e = Maybe a -> e -> a Source

An aggregate action is just a function for applying an event to an aggregate. Aggregates that have not been created yet will be passed in as Nothing and aggregates which are being updated will be passed in as Just x.

data Repository a e Source

Repository consisting of an event store and an event bus.

data CommandT a e m b Source

Command monad transformer.

createAggregate :: (MonadIO m, Monad m) => UUID -> (UnitOfWorkT a e (CommandT a e m) (Maybe a) -> UnitOfWorkT a e (CommandT a e m) b) -> CommandT a e m b Source

Create a new aggregate using the supplied unit of work. Throws a VersionConflict exception if there is already an aggregate with the given aggregate ID. NOTE: The exception may be thrown at the END of the unit of work, and so any operations in the unit of work that are lifted into the nested monad may be performed regardless. (This is due to optimistic concurrency control.)

execCommandT :: MonadIO m => Repository a e -> CommandT a e m b -> m () Source

Run a command against a repository, ignoring the result.

freshUUID :: MonadIO m => CommandT a e m UUID Source

Create a fresh UUID from the repository.

publishEvent :: (MonadIO m, NFData a, NFData e) => e -> UnitOfWorkT a e (CommandT a e m) () Source

Publish event for the current aggregate.

readAggregate :: MonadIO m => UUID -> CommandT a e m (Maybe a) Source

Read value of an aggregate if it exists. If any update needs to be performed on the aggregate, use of the getter function (see createAggregate and updateAggregate) should be preferred.

runCommandT :: MonadIO m => Repository a e -> CommandT a e m b -> m b Source

Run a command against a repository.

data UnitOfWorkT a e m b Source

Unit of work monad transformer.

updateAggregate :: MonadIO m => UUID -> (UnitOfWorkT a e (CommandT a e m) a -> UnitOfWorkT a e (CommandT a e m) b) -> CommandT a e m (Maybe b) Source

Update aggregate with the supplied unit of work. The unit of work is given a function to get the current value of the aggregate. Returns the value returned by the unit of work, or Nothing if there was no aggregate with the given ID. Throws a VersionConflict exception if a version conflict occurs during commit. NOTE: The exception may be thrown at the END of the unit of work, and so any operations in the unit of work that are lifted into the nested monad may be performed regardless. (This is due to optimistic concurrency control.)