Skip to main content

hypercall_db_diesel/
lib.rs

1//! Diesel persistence implementations for Hypercall.
2//!
3//! This crate provides the concrete Diesel-based implementations of the
4//! persistence traits defined in `hypercall-db`. It owns the schema definitions,
5//! model types, and all SQL execution.
6//!
7//! ## Architecture
8//!
9//! `hypercall-db` defines ORM-free traits and domain types. This crate implements
10//! those traits using Diesel ORM. Two main entry points:
11//!
12//! - [`DatabaseHandler`] -- sync r2d2 pool, implements engine-path traits
13//!   (orders, instruments, tiers, settlements, journal replay, archiver).
14//!   Used by the engine event loop and startup code.
15//! - [`DieselDb`] -- async deadpool via `diesel-async`, implements API-path
16//!   traits (analytics, integrity, liquidation, notifications, nonces, push,
17//!   usernames). Used by the REST/WS API handlers.
18//!
19//! ## Migrations
20//!
21//! Database migrations live in `../../migrations/` and are compiled into the binary
22//! via `diesel_migrations::embed_migrations!`. The `MIGRATIONS` constant is
23//! applied automatically when constructing a [`DatabaseHandler`] (unless
24//! `new_readonly` or `with_pool_no_migrations` is used). After running
25//! migrations, `ensure_enum_values` adds any new Postgres enum variants
26//! that cannot be expressed as standard Diesel migrations.
27
28pub mod analytics;
29pub mod archiver;
30pub mod bootstrap;
31pub mod catalog;
32pub mod competition;
33pub mod database_handler;
34pub mod db_auth;
35pub mod diesel_db;
36pub mod directive_outbox;
37pub mod engine_enums;
38pub mod engine_journal;
39pub mod event_handler;
40pub mod faucet;
41pub mod instruments;
42pub mod integrity;
43pub mod ledger_ops;
44pub mod liquidation;
45pub mod mmp;
46pub mod models;
47pub mod nonces;
48pub mod notifications;
49pub mod oracle;
50pub mod order_status_materialization;
51pub mod orders;
52pub mod pm_settlement;
53pub mod push;
54#[cfg(feature = "rds-iam")]
55pub mod rds_iam;
56pub mod replay;
57pub mod rfq;
58pub mod rsm_credit;
59pub mod schema;
60pub mod settlement_ops;
61pub mod settlements;
62pub mod snapshots;
63pub mod tiers;
64pub mod transaction;
65pub mod transaction_submitter;
66pub mod usernames;
67#[cfg(feature = "rsm-state")]
68pub mod validator_rsm;
69
70#[cfg(test)]
71pub(crate) mod test_helpers;
72
73/// Sync persistence handler (r2d2 pool). See [`database_handler`] module docs.
74pub use database_handler::{build_db_pool, DatabaseHandler, DbPool, DynConnectionManager};
75/// Database authentication configuration.
76pub use db_auth::DbAuthConfig;
77/// Async connection pool type alias for `diesel-async` + deadpool.
78pub use diesel_db::{AsyncDbPool, DieselDb};
79/// Scoped database transaction. See [`transaction`] module docs.
80pub use transaction::DieselTransaction;