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 verification through 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
- Reduce boilerplate code
Modules§
- 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
- Handle query generation with helper methods for execution.
- 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§
- Cursor
Destructure Error - DbOp
- DbOp
With Time - Entity
Events - A
Vecwrapper that manages event-stream of an entity with helpers for event-sourcing operations - EsQuery
- EsQuery
Flavor Flat - EsQuery
Flavor Nested - Generic
Event - Represent the events in raw deserialized format when loaded from database
- Nested
- OneTime
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 - 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_guardmacro. - Into
Events - Required trait for converting new entities into their initial events before persistence.
- Into
OneTime Executor - Into
OneTime Executor At - Parent
- Trait that entities implement for every field marked
#[es_entity(nested)]Will be auto-implemented when `#[derive(EsEntity)] is used. - Populate
Nested - Retryable
Into - TryFrom
Events - Required trait for re-constructing entities from their events in chronological order.
Type Aliases§
- Last
Persisted - An alias for iterator over the persisted events