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;
27pub mod context;
28pub mod db;
29pub mod error;
30pub mod events;
31pub mod forgettable;
32pub mod idempotent;
33mod macros;
34pub mod nested;
35pub mod one_time_executor;
36pub mod operation;
37pub mod pagination;
38pub mod query;
39pub mod traits;
40
41pub mod prelude {
42    //! Convenience re-export of crates that the derive macros reference in generated code.
43
44    pub use chrono;
45    pub use serde;
46    pub use serde_json;
47    pub use sqlx;
48    pub use uuid;
49
50    #[cfg(feature = "json-schema")]
51    pub use schemars;
52}
53
54#[doc(inline)]
55pub use context::*;
56#[doc(inline)]
57pub use error::*;
58pub use es_entity_macros::EsEntity;
59pub use es_entity_macros::EsEvent;
60pub use es_entity_macros::EsRepo;
61pub use es_entity_macros::es_event_context;
62pub use es_entity_macros::expand_es_query;
63pub use es_entity_macros::retry_on_concurrent_modification;
64#[doc(inline)]
65pub use events::*;
66#[doc(inline)]
67pub use forgettable::{Forgettable, ForgettableRef};
68#[doc(inline)]
69pub use idempotent::*;
70#[doc(inline)]
71pub use nested::*;
72#[doc(inline)]
73pub use one_time_executor::*;
74#[doc(inline)]
75pub use operation::*;
76#[doc(inline)]
77pub use pagination::*;
78#[doc(inline)]
79pub use query::*;
80#[doc(inline)]
81pub use traits::*;
82
83#[cfg(feature = "graphql")]
84pub mod graphql {
85    pub use async_graphql;
86    pub use base64;
87
88    #[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Copy)]
89    #[serde(transparent)]
90    pub struct UUID(crate::prelude::uuid::Uuid);
91    async_graphql::scalar!(UUID);
92    impl<T: Into<crate::prelude::uuid::Uuid>> From<T> for UUID {
93        fn from(id: T) -> Self {
94            let uuid = id.into();
95            Self(uuid)
96        }
97    }
98    impl From<&UUID> for crate::prelude::uuid::Uuid {
99        fn from(id: &UUID) -> Self {
100            id.0
101        }
102    }
103}