wal-backup 0.8.11

Embedded SQLite WAL replication to S3-compatible object storage. Not a sidecar — a library. Like Litestream, but embedded.
Documentation
//! Minimal embedded usage — the 5-line way to add S3 backup to your SQLite app.
//!
//! Run: `cargo run --example embedded`

use object_store::local::LocalFileSystem;
use std::sync::Arc;
use wal_backup::{Config, DurabilityLayer, ObjectStoreBucket};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tracing_subscriber::fmt::init();

    // 1. Create a local bucket (swap with AmazonS3Builder for real S3)
    let tmp = std::env::temp_dir().join("wal-backup-embedded-example");
    std::fs::create_dir_all(tmp.join("bucket"))?;
    let store = Arc::new(LocalFileSystem::new_with_prefix(tmp.join("bucket"))?);
    let bucket = Arc::new(ObjectStoreBucket::new(store, "my-app".to_string())?);

    // 2. Open — that's it. WAL frames ship automatically.
    let layer = DurabilityLayer::open(Config::new(tmp.join("app.db")), bucket).await?;

    // 3. Use SQLite normally
    {
        let conn = layer.conn().await;
        conn.execute_batch("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)")?;
        conn.execute("INSERT INTO users (name) VALUES ('Alice')", [])?;
    }

    // 4. Optional: force a sync before shutdown
    layer.sync_now().await?;

    // 5. Shutdown — checkpoints WAL, releases locks
    layer.shutdown().await?;
    println!("Done — your SQLite data is backed up to S3.");
    Ok(())
}