Expand description
§cqrs
cqrs
is an event-driven framework for writing software that uses events as
the “source of truth” and implements command–query responsibility separation (CQRS).
The framework is built around a few key concepts:
- Events: The things that happened in the system
- Aggregates: Projections of events that calculate a view of the current state of the system
- Commands: Intentions which, when executed against an aggregate, may produce zero or more events, or which may be prohibited by the current state of an aggregate
- Reactions: Processes that execute an action when certain events occur in the system
The framework is written to be applicable to a generic backend, with an implementation provided for a PostgreSQL backend.
For an example of how to construct a domain which includes aggregates, events,
and commands, look at the cqrs-todo-core
crate, which is a simple to-do list
implementation.
The source repository also contains a binary in the cqrs-todoql-psql
directory
which demonstrates the use of the todo
domain in concert with the PostgreSQL
backend and a GraphQL frontend using the juniper
crate.
Modules§
- memory
- A basic, in-memory event stream.
- reactor
- trivial
- Provides a trivial implementation of event/snapshot/entity source/sink/store constructs.
Structs§
- Always
Snapshot - A snapshot strategy that will always recommend taking a snapshot.
- Borrowed
RawEvent - An owned, raw view of event data.
- Composite
Entity Sink - Combines an
EventSink
and aSnapshotSink
of different types by reference so that they can be used jointly as an EntitySink. - Composite
Entity Source - Combines an
EventSource
and aSnapshotSource
of different types by reference so that they can be used jointly as an EntitySource. - Composite
Entity Store - Combines an EntitySource and an EntitySink into a single type so that they can be jointly used as an EntityStore.
- Entity
- An identified, specific instance of a hydrated aggregate.
- Event
Number - Represents an event sequence number, starting at 1
- Never
Snapshot - A snapshot strategy that will never recommend taking a snapshot.
- RawEvent
- An owned, raw view of event data.
- Versioned
Aggregate - A structured tuple combining an aggregate and its current version.
- Versioned
Event - A structured tuple combining an event number and an event.
- Versioned
Event With Metadata - A structured tuple combining an event number and an event.
Enums§
- Before
- The starting point when reading a stream of values from an [EventSource].
- Precondition
- A precondition that must be upheld for a command to be executed or for events to be persisted.
- Since
- The starting point when reading a stream of values from an [EventSource].
- Snapshot
Recommendation - A recommendation on whether or not a snapshot should be persisted.
- Version
- An aggregate version.
Traits§
- Aggregate
- A projected state built from a series of events.
- Aggregate
Command - A command that can be executed against an aggregate.
- Aggregate
Event - An event that can be applied to an aggregate.
- Aggregate
Id - An identifier for an aggregate.
- Cqrs
Error - Represents a common trait that all errors handled by CQRS should implement.
- Deserializable
Event - An event that can be deserialized from a buffer.
- Entity
Sink - A sink for persisting an Entity.
- Entity
Source - A source for loading an Entity.
- Entity
Store - A generalized entity store that can perform operations on its entities.
- Event
- A thing that happened.
- Event
Sink - A sink for writing/persisting events with associated metadata.
- Event
Source - A source for reading/loading events.
- Events
- An iterable and sliceable list of events.
- Serializable
Event - An event that can be serialized to a buffer.
- Snapshot
Sink - A sink for writing/persisting snapshots of aggregates.
- Snapshot
Source - A source for reading/loading snapshots of aggregates.
- Snapshot
Strategy - A strategy determining when to recommend a snapshot be taken.
Type Aliases§
- Command
Error - The error produced when this command cannot be executed against an aggregate.
- Produced
Event - The event type produced by this command.
- Produced
Events - The event sequence produced by this command.