persistant 0.21.0

A thin persistence layer over Apache OpenDAL for blobs and records by key: declared capabilities, atomic replace, typed records, and a blocking facade for synchronous callers.
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0
//! The relational kind: open through the registry, run statements with parameters in a transaction.
//!
//! `cargo run --example relational --features registry-sqlite` (a temporary SQLite file). Statements
//! are written in the dialect the backend reports; nothing here translates SQL.

use persistant::capability::{CapabilityId, choose::Durability, provider::ProviderNeeds};
use persistant::registry::{self, Endpoint};
use persistant::relational::{Isolation, RelationalBackend, RelationalTx, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // What the program needs; a backend that cannot give it is refused at the open.
    let ids = ["rel.transaction"].map(|s| CapabilityId::new(s).expect("well formed"));
    let needs = ProviderNeeds::new(ids.to_vec(), Durability::Process);

    let dir = tempfile::tempdir()?;
    let endpoint = Endpoint::path(dir.path().join("example.db"));
    let handle = registry::open_named("sqlite", &endpoint, &needs).await?;
    let db = handle
        .rel()
        .expect("a `rel.*` need gives a relational handle");

    db.execute(
        "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL)",
        &[],
    )
    .await?;

    // Committed together, or not at all.
    let mut tx = db.begin(Isolation::ReadCommitted).await?;
    for (id, name) in [(1, "ada"), (2, "grace")] {
        tx.execute(
            "INSERT INTO users (id, name) VALUES ($1, $2)",
            &[Value::Int(id), Value::Text(name.into())],
        )
        .await?;
    }
    tx.commit().await?;

    // Dropped without `commit`: rolled back.
    let mut tx = db.begin(Isolation::ReadCommitted).await?;
    tx.execute("DELETE FROM users", &[]).await?;
    drop(tx);

    let rows = db
        .query("SELECT name FROM users WHERE id = $1", &[Value::Int(2)])
        .await?;
    assert_eq!(rows.len(), 1);
    println!("{rows:?}");
    assert_eq!(db.query("SELECT id FROM users", &[]).await?.len(), 2);
    Ok(())
}