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