Getting started
Graven schemas (.graven) are language-neutral. The gravenc compiler validates schemas,
tracks compatibility in <schema>.lock, inspects binary files, and generates code.
1. Install gravenc
cargo install graven-compiler
(Or from a source checkout: cargo build --release -p graven-compiler --bin gravenc.)
2. Write a schema and create its lockfile
Create schemas/bank.graven:
namespace bank;
enum Currency : u16 { BRL = 0, USD = 1, EUR = 2 }
table Entry {
account @0: u64;
amount @1: i64;
memo @2: string?;
}
table Transaction {
id @0: u64;
ts @1: u64;
currency @2: Currency;
from_shard @3: u32;
to_shard @4: u32;
entries @5: [Entry];
note @6: string?;
}
Initialize its lockfile once:
gravenc update schemas/bank.graven --init
The lockfile (schemas/bank.graven.lock) records every table's schema_id, fixed-part
layout, defaults, and validation rules. Commit it alongside your .graven files.
3. Evolve, check, and generate
- Check in CI:
gravenc check --locked schemas/*.graven - Update after changes:
gravenc update schemas/bank.graven(refuses breaking changes) - Generate code from the CLI:
gravenc gen schemas/bank.graven -o generated/ - Inspect / convert binary data:
gravenc inspect,gravenc to-json,gravenc from-json
Because <schema>.lock records the resolved layout and schema_ids, generators for other
languages can target the lockfile directly without reimplementing the layout rules.
Option: Rust project (Cargo.toml + build.rs)
If you are using Rust, you can run code generation automatically during cargo build
instead of invoking gravenc gen manually:
-
Install the compiler:
cargo install graven-compiler(providesgravenc). Add the runtime and the code generator to your crate'sCargo.toml:[dependencies] graven = "0.2" [build-dependencies] graven-compiler = "0.2" -
Write
schemas/bank.gravenand create its lockfile once:gravenc update schemas/bank.graven --init. -
Generate code from
build.rs(it reads the lock and never writes it):fn main() { graven_compiler::build::Build::new() .schema("schemas/bank.graven") .compile() .unwrap_or_else(|e| panic!("{e}")); } -
Include the generated file alone in its own module:
pub mod bank { include!(concat!(env!("OUT_DIR"), "/bank.rs")); } -
When the schema changes, run
gravenc update schemas/bank.graven: it checks compatibility against the lock before rewriting it. In CI,gravenc check --locked schemas/*.graven.
Next steps
- Coming from JSON — translate existing JSON data into a Graven schema.
- Schema language — grammar, evolution rules, and the generated API.
- Validation — built-in rules (
range,len,finite,known) and customcheck(name)hooks. - Tools —
diff,inspect,to-json,from-json,scan, and editor support.