Crate es_entity

Crate es_entity 

Source
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§

ContextData
Immutable context data that can be safely shared across thread boundaries.
CursorDestructureError
DbOp
Default return type of the derived EsRepo::begin_op().
DbOpWithTime
Equivileant of DbOp just that the time is guaranteed to be cached.
EntityEvents
A Vec wrapper that manages event-stream of an entity with helpers for event-sourcing operations
EsQuery
Query builder for event-sourced entities.
EsQueryFlavorFlat
Query flavor for flat entities without nested relationships.
EsQueryFlavorNested
Query flavor for entities with nested relationships that need to be loaded recursively.
EventContext
Thread-local event context for tracking metadata throughout event sourcing operations.
EventContextFuture
A future wrapper that provides event context during polling.
EventWithContext
GenericEvent
Represent the events in raw deserialized format when loaded from database
Nested
OneTimeExecutor
A struct that owns an sqlx::Executor.
PaginatedQueryArgs
A cursor-based pagination structure for efficiently paginating through large datasets
PaginatedQueryRet
Return type for paginated queries containing entities and pagination metadata
PersistedEvent
Strongly-typed event wrapper with metadata for successfully stored events.
Sort
Structure to sort entities on a specific field when listing from database

Enums§

EsEntityError
EsRepoError
Idempotent
Signals if a mutation is applied or was skipped.
ListDirection
Controls the sorting order when listing the entities from the database

Traits§

AtomicOperation
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.
FromIdempotentIgnored
Internal trait used by the idempotency_guard macro.
IntoEvents
Required trait for converting new entities into their initial events before persistence.
IntoOneTimeExecutor
Marker trait for IntoOneTimeExecutorAt<'a> + 'a. Do not implement directly.
IntoOneTimeExecutorAt
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)]
PopulateNested
RetryableInto
TryFromEvents
Required trait for re-constructing entities from their events in chronological order.
WithEventContext
Extension trait for propagating event context across async boundaries.

Type Aliases§

LastPersisted
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

Derive Macros§

EsEntity
EsEvent
EsRepo