Valence

Transparent, policy-aware data

Valence is a schema-driven ORM for Rust: privacy-aware models, composable storage adapters, and host-injectable ports. Wire backends at boot via Valence::builder() — trait ports in valence-core, engines in feature-gated valence-backend-* crates.

Why this family exists

Product data should be typed and policy-aware without locking you into one database. Valence owns the ORM surface—schema registry, privacy and ownership hooks, query routing, and the DatabaseBackend port—while your application owns schemas, codegen roots, and business logic. Storage engines live in separate adapter crates so you can start on mem and grow into SQLite, Surreal, Postgres, MongoDB, Redis, or IndraDB.

Where it lands

Unified Field apps compile Valence schemas into Model APIs and bind them through Valence::builder() so counters, identity, and product tables share one transparency layer across backends.
Define schemas with valence_schema!, generate Model APIs via valence-codegen in build.rs, and register backends through ValenceBuilder. One runtime may host heterogeneous engines; each operation stays on one backend. Host-specific ports (secrets, actor, endpoints, telemetry) inject at boot so privacy evaluation and ownership stay next to the data model instead of being bolted on later. Published as uf-valence on crates.io; Rust imports stay use valence::….

In the workspace

Unified Field apps compile Valence schemas into Model APIs and bind them through Valence::builder() so counters, identity, and product tables share one transparency layer across backends.

Code sample

From the upstream getting-started docs — see also all code recipes on Resources.
Valence schemaValence
Schema DSL + builder backends
use std::sync::Arc;
use valence::{
    Database, DatabaseFromEngine, FieldType, InMemoryBackend, Valence, MEM_ENGINE_ID,
    valence_schema,
};

const COUNTER_DB: DatabaseFromEngine = Database::from_engine("default", MEM_ENGINE_ID);

valence_schema! {
    Counter {
        table: "counter",
        version: "0.1.0",
        description: "Simple counter",
        database: COUNTER_DB,
        fields: [
            id: { r#type: FieldType::String, primary_key: true, required: true },
            value: { r#type: FieldType::Integer, required: true },
        ],
    }
}

let valence = Valence::builder()
    .add_backend("default", Arc::new(InMemoryBackend::new()))
    .build()?;