Expand description
A Rust library for persisting Event Sourced entities to PostgreSQL
This crate simplifies Event Sourcing persistence by automatically generating type-safe queries and operations for PostgreSQL. It decouples domain logic from persistence concerns while ensuring compile-time query verification via sqlx.
§Documentation
§Features
- Store and construct from event sequences
- Type-safe and compile-time verification
- Simple and configurable query generation
- Easy idempotency checks
- Cursor-based pagination
- Flexible ID types
- Atomic operations
Modules§
- context
- Thread-local system for adding context data to persisted events.
- error
- Types for working with errors produced by es-entity.
- events
- Manage events and related operations for event-sourcing.
- idempotent
- Handle idempotency in event-sourced systems.
- nested
- Handle operations for nested entities.
- one_
time_ executor - Type-safe wrapper to ensure one database operation per executor.
- operation
- Handle execution of database operations and transactions.
- pagination
- Control and customize the query execution and its response.
- prelude
- Convenience re-export of crates that the derive macros reference in generated code.
- query
- Query execution infrastructure for event-sourced entities.
- traits
- Traits to orchestrate and maintain the event-sourcing pattern.
Macros§
- entity_
id - Create UUID-wrappers for database operations.
- es_
query - Execute an event-sourced query with automatic entity hydration.
- from_
es_ entity_ error - idempotency_
guard - Prevent duplicate event processing by checking for idempotent operations.
Structs§
- Context
Data - Immutable context data that can be safely shared across thread boundaries.
- Cursor
Destructure Error - DbOp
- Default return type of the derived EsRepo::begin_op().
- DbOp
With Time - Equivileant of
DbOp
just that the time is guaranteed to be cached. - Entity
Events - A
Vec
wrapper that manages event-stream of an entity with helpers for event-sourcing operations - EsQuery
- Query builder for event-sourced entities.
- EsQuery
Flavor Flat - Query flavor for flat entities without nested relationships.
- EsQuery
Flavor Nested - Query flavor for entities with nested relationships that need to be loaded recursively.
- Event
Context - Thread-local event context for tracking metadata throughout event sourcing operations.
- Event
Context Future - A future wrapper that provides event context during polling.
- Event
With Context - Generic
Event - Represent the events in raw deserialized format when loaded from database
- Nested
- OneTime
Executor - A struct that owns an
sqlx::Executor
. - Paginated
Query Args - A cursor-based pagination structure for efficiently paginating through large datasets
- Paginated
Query Ret - Return type for paginated queries containing entities and pagination metadata
- Persisted
Event - Strongly-typed event wrapper with metadata for successfully stored events.
- Sort
- Structure to sort entities on a specific field when listing from database
Enums§
- EsEntity
Error - EsRepo
Error - Idempotent
- Signals if a mutation is applied or was skipped.
- List
Direction - Controls the sorting order when listing the entities from the database
Traits§
- Atomic
Operation - Trait to signify we can make multiple consistent database roundtrips.
- EsEntity
- Required trait for all entities to be compatible and recognised by es-entity.
- EsEvent
- Required trait for all event enums to be compatible and recognised by es-entity.
- EsRepo
- Required trait for all repositories to be compatible with es-entity and generate functions.
- From
Idempotent Ignored - Internal trait used by the
idempotency_guard
macro. - Into
Events - Required trait for converting new entities into their initial events before persistence.
- Into
OneTime Executor - Marker trait for
IntoOneTimeExecutorAt<'a> + 'a
. Do not implement directly. - Into
OneTime Executor At - A trait to signify that we can use an argument for 1 round trip to the database
- Parent
- Trait that entities implement for every field marked
#[es_entity(nested)]
- Populate
Nested - Retryable
Into - TryFrom
Events - Required trait for re-constructing entities from their events in chronological order.
- With
Event Context - Extension trait for propagating event context across async boundaries.
Type Aliases§
- Last
Persisted - An alias for iterator over the persisted events
Attribute Macros§
- es_
event_ context - Automatically captures function arguments into the event context.
- retry_
on_ concurrent_ modification