Skip to main content

evento_sql/
lib.rs

1//! SQL database implementations for the Evento event sourcing library.
2//!
3//! This crate provides SQL-based persistence for events and subscriber state, supporting
4//! SQLite, MySQL, and PostgreSQL through feature flags.
5//!
6//! # Features
7//!
8//! - **`sqlite`** - Enables SQLite database support
9//! - **`mysql`** - Enables MySQL database support
10//! - **`postgres`** - Enables PostgreSQL database support
11//!
12//! All features are enabled by default. You can selectively enable only the databases you need:
13//!
14//! ```toml
15//! [dependencies]
16//! evento-sql = { version = "1.8", default-features = false, features = ["postgres"] }
17//! ```
18//!
19//! # Usage
20//!
21//! The main type is [`Sql<DB>`], a generic wrapper around a SQLx connection pool that
22//! implements the [`Executor`](evento_core::Executor) trait for event sourcing operations.
23//!
24//! ## Quick Start
25//!
26//! ```rust,ignore
27//! use evento_sql::Sql;
28//! use sqlx::sqlite::SqlitePoolOptions;
29//!
30//! // Create a connection pool
31//! let pool = SqlitePoolOptions::new()
32//!     .connect(":memory:")
33//!     .await?;
34//!
35//! // Wrap it in the Sql executor
36//! let executor: Sql<sqlx::Sqlite> = pool.into();
37//!
38//! // Use with Evento for event sourcing operations
39//! ```
40//!
41//! ## Type Aliases
42//!
43//! Convenience type aliases are provided for each database:
44//!
45//! - [`Sqlite`] - `Sql<sqlx::Sqlite>`
46//! - [`MySql`] - `Sql<sqlx::MySql>`
47//! - [`Postgres`] - `Sql<sqlx::Postgres>`
48//!
49//! Read-write pair types for CQRS patterns:
50//!
51//! - [`RwSqlite`] - Read/write SQLite executor pair
52//! - [`RwMySql`] - Read/write MySQL executor pair
53//! - [`RwPostgres`] - Read/write PostgreSQL executor pair
54//!
55//! # Core Components
56//!
57//! - [`Sql`] - The main executor type wrapping a SQLx connection pool
58//! - [`Reader`] - Query builder for reading events with cursor-based pagination
59//! - [`Bind`] - Trait for cursor serialization in paginated queries
60//! - [`Event`], [`Subscriber`], [`Snapshot`] - Sea-Query column identifiers
61//!
62//! # Serialization
63//!
64//! The [`sql_types`] module provides the [`Bitcode`](sql_types::Bitcode) wrapper for compact
65//! binary serialization of event data using the bitcode format.
66
67mod sql;
68pub mod sql_types;
69
70pub use sql::*;