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