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    Carrier, CodeInfo, Denied, Fail, Fatal, FatalKind, Fault, Lane, Laned, Lift, Rejection,
69    RejectionCode, ResultExt, Transient, TransientKind, WithDenied, WithoutDenied,
70    WithoutTransient,
71};
72#[doc(inline)]
73pub use error::*;
74#[doc(hidden)]
75pub use es_entity_macros::ConstraintRejection;
76pub use es_entity_macros::EsEntity;
77pub use es_entity_macros::EsEvent;
78pub use es_entity_macros::EsRepo;
79pub use es_entity_macros::EsSnapshot;
80pub use es_entity_macros::es_event_context;
81pub use es_entity_macros::expand_es_query;
82#[doc(inline)]
83pub use events::*;
84#[doc(inline)]
85pub use forgettable::{Forgettable, ForgettableRef};
86#[doc(inline)]
87pub use id_source::{Ensured, EntityEventsBuilder, FromCaller, FromRepo, IdSource};
88#[doc(inline)]
89pub use idempotent::*;
90#[doc(inline)]
91pub use nested::*;
92#[doc(inline)]
93pub use one_time_executor::*;
94#[doc(inline)]
95pub use operation::*;
96#[doc(inline)]
97pub use pagination::*;
98#[doc(inline)]
99pub use query::*;
100#[doc(inline)]
101pub use snapshot::*;
102#[doc(inline)]
103pub use traits::*;
104#[doc(inline)]
105pub use tree_query::*;
106#[doc(inline)]
107pub use write_shape::{Faults, LiftNestedWrite, Rejects, WriteShape, WriteShapes};
108
109#[cfg(feature = "graphql")]
110pub mod graphql {
111    pub use async_graphql;
112    pub use base64;
113
114    #[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Copy)]
115    #[serde(transparent)]
116    pub struct UUID(crate::prelude::uuid::Uuid);
117    async_graphql::scalar!(UUID);
118    impl<T: Into<crate::prelude::uuid::Uuid>> From<T> for UUID {
119        fn from(id: T) -> Self {
120            let uuid = id.into();
121            Self(uuid)
122        }
123    }
124
125    impl From<&UUID> for crate::prelude::uuid::Uuid {
126        fn from(id: &UUID) -> Self {
127            id.0
128        }
129    }
130}