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

CursorDestructureError
DbOp
DbOpWithTime
EntityEvents
A Vec wrapper that manages event-stream of an entity with helpers for event-sourcing operations
EsQuery
EsQueryFlavorFlat
EsQueryFlavorNested
GenericEvent
Represent the events in raw deserialized format when loaded from database
Nested
OneTimeExecutor
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
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
IntoOneTimeExecutorAt
Parent
Trait that entities implement for every field marked #[es_entity(nested)] Will be auto-implemented when `#[derive(EsEntity)] is used.
PopulateNested
RetryableInto
TryFromEvents
Required trait for re-constructing entities from their events in chronological order.

Type Aliases§

LastPersisted
An alias for iterator over the persisted events

Attribute Macros§

retry_on_concurrent_modification

Derive Macros§

EsEntity
EsEvent
EsRepo