Get started

Clone the repository, run the executor's tests against PostgreSQL 18, then run your own schema and programs from Rust.

Prerequisites: Git, rustup (the repository selects Rust 1.99.0 in rust-toolchain.toml) and a PostgreSQL 18 server. Without FIREWEED_PG_TEST_URL the executor's tests skip.

1. Run the tests

clone and testsh
git clone https://github.com/7thsense/fireweed.git
cd fireweed
# A PostgreSQL 18 server for the executor's tests; any reachable one works.
docker run --rm -d --name fireweed-pg -e POSTGRES_PASSWORD=fireweed \
  -p 127.0.0.1:5432:5432 postgres:18
FIREWEED_PG_TEST_URL=postgres://postgres:fireweed@127.0.0.1:5432/postgres \
  cargo test --workspace

The tests in crates/fireweed-dsl-postgres/tests/executor.rs run schema and program documents against PostgreSQL and check the responses and the rows left behind. Each test uses its own space.

2. Run a program from Rust

Depend on the crates from crates.io.

Cargo.tomltoml
[dependencies]
fireweed-dsl = "0.37"
fireweed-dsl-postgres = "0.37"
serde_json = "1"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
docs/site/examples/src/embed.rsrust
use std::sync::Arc;

use fireweed_dsl::{Executor, Program, Schema, from_yaml};
use fireweed_dsl_postgres::PgExecutor;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // The host picks the backend; the rest of the code sees only `Executor`.
    let url = std::env::var("DATABASE_URL")?;
    let engine: Arc<dyn Executor> = Arc::new(PgExecutor::new(url.parse()?));

    // Create the space, or leave it as it is if the schema is unchanged.
    let schema: Schema = from_yaml(&std::fs::read_to_string("schema.yaml")?)?;
    engine
        .apply_schema("acme", "campaign-c7", &schema, None)
        .await?;

    // Run one program as one transaction.
    let program: Program = from_yaml(&std::fs::read_to_string("program.yaml")?)?;
    let response = engine.execute("acme", "campaign-c7", &program).await?;
    println!("{}", serde_json::to_string_pretty(&response)?);
    Ok(())
}

For schema.yaml, use the examples' shared schema; for program.yaml, any program from the examples. Set issued_at to the current time: a request issued more than request_retention (default one day) ago fails with request_expired, and one more than 5 minutes ahead of the database clock is invalid.

Next