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();
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())?);
let layer = DurabilityLayer::open(Config::new(tmp.join("app.db")), bucket).await?;
{
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')", [])?;
}
layer.sync_now().await?;
layer.shutdown().await?;
println!("Done — your SQLite data is backed up to S3.");
Ok(())
}