Skip to main content

es_entity/
lib.rs

1//! A Rust library for persisting Event Sourced entities to PostgreSQL
2//!
3//! This crate simplifies Event Sourcing persistence by automatically generating type-safe
4//! queries and operations for PostgreSQL. It decouples domain logic from persistence
5//! concerns while ensuring compile-time query verification via [sqlx](https://crates.io/crates/sqlx).
6//!
7//! # Documentation
8//! - [Book](https://galoymoney.github.io/es-entity)
9//! - [Github repository](https://github.com/GaloyMoney/es-entity)
10//! - [Cargo package](https://crates.io/crates/es-entity)
11//!
12//! # Features
13//!
14//! - Store and construct from event sequences
15//! - Type-safe and compile-time verification
16//! - Simple and configurable query generation
17//! - Easy idempotency checks
18//! - Cursor-based pagination
19//! - Flexible ID types
20//! - Atomic operations
21
22#![cfg_attr(feature = "fail-on-warnings", deny(warnings))]
23#![cfg_attr(feature = "fail-on-warnings", deny(clippy::all))]
24#![forbid(unsafe_code)]
25
26pub mod clock;
27mod constraint;
28pub mod context;
29pub mod db;
30pub mod error;
31pub use constraint::*;
32pub mod events;
33pub mod forgettable;
34pub mod id_source;
35pub mod idempotent;
36mod macros;
37pub mod nested;
38pub mod one_time_executor;
39pub mod operation;
40pub mod pagination;
41pub mod query;
42pub mod snapshot;
43pub mod sql_commenter;
44#[cfg(feature = "testing")]
45pub mod testing;
46pub mod traits;
47pub mod tree_query;
48pub mod write_shape;
49
50pub mod prelude {
51    //! Convenience re-export of crates that the derive macros reference in generated code.
52
53    pub use chrono;
54    pub use serde;
55    pub use serde_json;
56    pub use sqlx;
57    pub use tokio;
58    pub use uuid;
59
60    #[cfg(feature = "json-schema")]
61    pub use schemars;
62}
63
64#[doc(inline)]
65pub use context::*;
66pub use errlanes;
67pub use errlanes::{
68    CodeInfo, Denied, Fail, Fatal, FatalKind, Fault, Lane, Laned, Lift, Rejection, RejectionCode,
69    ResultExt, Transient, TransientKind, WithDenied, WithoutDenied, WithoutTransient,
70};
71#[doc(inline)]
72pub use error::*;
73#[doc(hidden)]
74pub use es_entity_macros::ConstraintRejection;
75pub use es_entity_macros::EsEntity;
76pub use es_entity_macros::EsEvent;
77pub use es_entity_macros::EsRepo;
78pub use es_entity_macros::EsSnapshot;
79pub use es_entity_macros::es_event_context;
80pub use es_entity_macros::expand_es_query;
81#[doc(inline)]
82pub use events::*;
83#[doc(inline)]
84pub use forgettable::{Forgettable, ForgettableRef};
85#[doc(inline)]
86pub use id_source::{Ensured, EntityEventsBuilder, FromCaller, FromRepo, IdSource};
87#[doc(inline)]
88pub use idempotent::*;
89#[doc(inline)]
90pub use nested::*;
91#[doc(inline)]
92pub use one_time_executor::*;
93#[doc(inline)]
94pub use operation::*;
95#[doc(inline)]
96pub use pagination::*;
97#[doc(inline)]
98pub use query::*;
99#[doc(inline)]
100pub use snapshot::*;
101#[doc(inline)]
102pub use traits::*;
103#[doc(inline)]
104pub use tree_query::*;
105#[doc(inline)]
106pub use write_shape::{Faults, LiftNestedWrite, Rejects, WriteShape, WriteShapes};
107
108#[cfg(feature = "graphql")]
109pub mod graphql {
110    pub use async_graphql;
111    pub use base64;
112
113    #[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Copy)]
114    #[serde(transparent)]
115    pub struct UUID(crate::prelude::uuid::Uuid);
116    async_graphql::scalar!(UUID);
117    impl<T: Into<crate::prelude::uuid::Uuid>> From<T> for UUID {
118        fn from(id: T) -> Self {
119            let uuid = id.into();
120            Self(uuid)
121        }
122    }
123
124    impl From<&UUID> for crate::prelude::uuid::Uuid {
125        fn from(id: &UUID) -> Self {
126            id.0
127        }
128    }
129}