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 idempotent;
35mod macros;
36pub mod nested;
37pub mod one_time_executor;
38pub mod operation;
39pub mod pagination;
40pub mod query;
41pub mod snapshot;
42pub mod sql_commenter;
43pub mod traits;
44pub mod tree_query;
45
46pub mod prelude {
47    //! Convenience re-export of crates that the derive macros reference in generated code.
48
49    pub use chrono;
50    pub use serde;
51    pub use serde_json;
52    pub use sqlx;
53    pub use tokio;
54    pub use uuid;
55
56    #[cfg(feature = "json-schema")]
57    pub use schemars;
58}
59
60#[doc(inline)]
61pub use context::*;
62pub use errlanes;
63pub use errlanes::{
64    Carrier, CodeInfo, Denied, Fail, Fatal, FatalKind, Fault, Lane, Laned, Lift, Rejection,
65    RejectionCode, ResultExt, Transient, TransientKind, WithDenied, WithoutDenied,
66    WithoutTransient,
67};
68#[doc(inline)]
69pub use error::*;
70#[doc(hidden)]
71pub use es_entity_macros::ConstraintRejection;
72pub use es_entity_macros::EsEntity;
73pub use es_entity_macros::EsEvent;
74pub use es_entity_macros::EsRepo;
75pub use es_entity_macros::EsSnapshot;
76pub use es_entity_macros::es_event_context;
77pub use es_entity_macros::expand_es_query;
78#[doc(inline)]
79pub use events::*;
80#[doc(inline)]
81pub use forgettable::{Forgettable, ForgettableRef};
82#[doc(inline)]
83pub use idempotent::*;
84#[doc(inline)]
85pub use nested::*;
86#[doc(inline)]
87pub use one_time_executor::*;
88#[doc(inline)]
89pub use operation::*;
90#[doc(inline)]
91pub use pagination::*;
92#[doc(inline)]
93pub use query::*;
94#[doc(inline)]
95pub use snapshot::*;
96#[doc(inline)]
97pub use traits::*;
98#[doc(inline)]
99pub use tree_query::*;
100
101#[cfg(feature = "graphql")]
102pub mod graphql {
103    pub use async_graphql;
104    pub use base64;
105
106    #[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Copy)]
107    #[serde(transparent)]
108    pub struct UUID(crate::prelude::uuid::Uuid);
109    async_graphql::scalar!(UUID);
110    impl<T: Into<crate::prelude::uuid::Uuid>> From<T> for UUID {
111        fn from(id: T) -> Self {
112            let uuid = id.into();
113            Self(uuid)
114        }
115    }
116
117    impl From<&UUID> for crate::prelude::uuid::Uuid {
118        fn from(id: &UUID) -> Self {
119            id.0
120        }
121    }
122}