wal-backup 0.8.11

Embedded SQLite WAL replication to S3-compatible object storage. Not a sidecar — a library. Like Litestream, but embedded.
Documentation
//! # wal-backup
//!
//! Embedded SQLite WAL replication to S3-compatible object storage.
//!
//! **Not a sidecar — a library.** Your app links the crate, calls
//! [`DurabilityLayer::open()`], and gets automatic S3 backup in the background.
//!
//! # Architecture
//!
//! ```text
//! Your App → DurabilityLayer → SQLite DB (local, fast)
//!                          └→ S3 Bucket (backup, source of truth)
//! ```
//!
//! One process, one DB, one bucket prefix. Always.
//! The bucket is a backup, not a replication bus.
//!
//! # Quick Start
//!
//! ```ignore
//! use std::sync::Arc;
//! use wal_backup::{Config, DurabilityLayer, ObjectStoreBucket, SyncMode};
//!
//! let store = wal_backup::build_s3_store_from_env("my-bucket")?;
//! let bucket = Arc::new(
//!     ObjectStoreBucket::new(store, "my-app".to_string())?
//!         .with_writer_id("server-1"),
//! );
//!
//! let config = Config::new("/data/my.db")
//!     .with_sync_mode(SyncMode::Immediate);
//!
//! let layer = DurabilityLayer::open(config, bucket).await?;
//!
//! // Write SQL — WAL frames ship to S3 automatically
//! layer.with_conn(|conn| {
//!     conn.execute("INSERT INTO users (name) VALUES (?)", ["Alice"])
//! }).await?;
//!
//! // Graceful shutdown: checkpoint + final sync + release locks
//! layer.shutdown().await?;
//! ```
//!
//! # Multi-writer protection
//!
//! Two processes writing to the same bucket prefix = silent data corruption.
//! wal-backup prevents this at three levels:
//!
//! - **flock** (`.db.lock`): Two processes, same machine, same DB → [`Error::DatabaseLocked`]
//! - **lock.json** (bucket): Two processes, anywhere, same prefix → [`Error::ReplicaLocked`]
//! - **writer.json** (bucket): Wrong server opening the wrong prefix → [`Error::WrongWriter`]
//!
//! # Error handling
//!
//! ```ignore
//! match DurabilityLayer::open(config, bucket).await {
//!     Err(e) if e.is_database_locked() => { /* another process on this machine */ }
//!     Err(e) if e.is_replica_locked() => { /* another process anywhere */ }
//!     Err(e) if e.is_wrong_writer() => { /* wrong bucket prefix */ }
//!     Err(e) => return Err(e.into()),
//!     Ok(layer) => { /* use it */ }
//! }
//! ```

pub mod config;
pub mod connection;
pub mod error;
pub mod metrics;
pub mod replication;
pub mod restore;
pub mod storage;
pub mod util;
pub mod wal;

pub use config::{Config, RestoreBehavior, SyncMode};
pub use connection::DurabilityLayer;
pub use connection::HealthReport;
pub use error::{Error, Result};

#[cfg(feature = "compression")]
pub use storage::compressed::CompressedBucketStore;
#[cfg(feature = "encryption")]
pub use storage::encrypted::EncryptedBucketStore;
pub use storage::object_store_util::build_s3_store;
pub use storage::object_store_util::build_s3_store_from_env;
pub use storage::BucketStore;
pub use storage::ObjectStoreBucket;

pub use metrics::{noop_metrics, Metrics, NoopMetrics};
pub use replication::manifest::L1File;
pub use replication::manifest::Manifest;

pub use util::compute_sha256_file;
pub use wal::WalFile;
pub use wal::WalFrame;
pub use wal::WalHeader;