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