NEW RasterizedDB 1.1.0 is out: sharding and the gateway, the message broker, roles and row-level security, compression, .NET on NuGet, and the enterprise edition. What's new ›
RUST SDKS

A client, an ORM,
and the engine itself.

rasterizeddb_client speaks the native protocol and carries an ORM, migrations and a KV API. rasterizeddb_embedded runs the whole engine inside your process behind that same client. Start embedded, move to a server by changing one line.

rasterizeddb_client

Typed queries over rastcp.

Rows decode by position into tuples, structs or values, and a select list that drifted from the code is an error at once, not a silent shift. Connections are multiplexed; a connection the server closed is reopened by the next statement.

  • TCP with TLS, or a unix socket with peer auth
  • fetch_all, fetch_one, fetch_optional, fetch_scalar
  • Typed NUMERIC, UUID, timestamps, JSON, arrays
  • No engine compiled in: a small dependency
queries.rs
use rasterizeddb_client::prelude::*;

let client = Client::connect("127.0.0.1:61170", Options::default()).await?;

let open: Vec<Order> = client
    .fetch_all(
        "SELECT id, customer, total::text, shipped FROM orders
         WHERE shipped IS NULL AND total > $1",
        params![Numeric::new("100")?],
    )
    .await?;
let count: i64 = client.fetch_scalar("SELECT COUNT(*) FROM orders", params![]).await?;
models.rs
#[derive(Model, Debug, Clone)]
#[rdb(table = "accounts")]
struct Account {
    #[rdb(primary_key, serial)]
    id: i64,
    #[rdb(unique)]
    email: String,
    #[rdb(index)]
    name: Option<String>,
    plan: Plan,
    balance: Numeric,
    #[rdb(version)]
    version: i64,
    created_at: Timestamp,
}

let rich = Account::query()
    .filter(Account::balance.gt(Numeric::new("10")?) & Account::name.is_not_null())
    .all(&client)
    .await?;
ORM

#[derive(Model)]

One struct is the table, the row type and the query builder's columns. Typed column constants make a misspelt column a compile error.

  • Relations: has_many, has_one, belongs_to, many_to_many
  • Optimistic locking with #[rdb(version)]
  • created_at / updated_at, soft delete
  • Upserts, RETURNING, bulk update as one CASE statement
  • Keyset pagination and streaming
  • Partitioning declared on the model; shard keys declared with #[rdb(shard_by = …)]
MIGRATIONS

Checked before anything runs.

The migrator checks every statement of every step before the first one runs, so a typo in step three cannot leave steps one and two applied. Options::auto_migrate applies or verifies at connect.

migrate.rs
fn migrations() -> Migrator {
    Migrator::new()
        .step("0001_settings", &[
            "CREATE TABLE IF NOT EXISTS settings (k TEXT NOT NULL, v TEXT, PRIMARY KEY (k))",
        ])
}
transfer.rs
let new_balance = client
    .transaction(|tx| Box::pin(async move {
        let balance: i64 = tx
            .fetch_scalar("SELECT balance FROM account WHERE id = $1", params![1])
            .await?;
        tx.exec("UPDATE account SET balance = $1 WHERE id = $2",
                params![balance - 10, 1]).await?;
        Ok(balance - 10)
    }))
    .await?;
TRANSACTIONS

Retried for you.

Each transaction runs on its own rastcp/1 connection. A serialization failure or deadlock is retried. A connection lost mid-block is reported with whether the commit's outcome is known.

Code written against the Executor trait runs on a client or inside a transaction, unchanged.

KV

The cache, typed.

KvRepo stores a Model as a hash under its primary key; the same struct the ORM maps. client.cached reads through: the table first, then the cache.

cache.rs
let profiles = client.cached::<Profile>(Duration::from_secs(30));
let p = profiles.find(7i64).await?;   // the table, then cached
main.rsrasterizeddb_embedded
use rasterizeddb_embedded::Builder;

let db = Builder::open("./data").start().await?;   // or Builder::in_memory()
let client = db.connect().await?;

client.execute("CREATE TABLE IF NOT EXISTS notes (id BIGINT, body TEXT)", &[]).await?;
client.execute("INSERT INTO notes VALUES (1, 'hello')", &[]).await?;

db.shutdown().await?;   // drains, seals the index snapshots, checkpoints the WAL
EMBEDDED

The engine in your process.

The full engine runs on a thread of its own with the server's 32 MiB stacks. You talk to it through rasterizeddb_client, so typed queries, transactions, the ORM, migrations and KV work unchanged.

  • Every server flag is a Builder method
  • A low_memory preset for small machines
  • Your signals stay yours: the engine never installs a Ctrl+C handler
  • Several databases from one engine with CREATE DATABASE
ALL THE KNOBS →
GET STARTED

Running in one command.

Linux and Windows, x86-64 and ARM64, a static musl build, an Arch package, or Docker.

terminalDOCKER
# PostgreSQL on 5432, native on 61170
docker run -d --name rasterizeddb \
  -e RASTERIZEDDB_PG_PASSWORD=change-me \
  -p 5432:5432 -p 61170:61170 \
  -v rasterizeddb:/var/lib/rasterizeddb \
  milendenev/rasterizeddb:latest

psql "postgresql://superuser@127.0.0.1:5432/postgres"
✓ page rendered in 58 µs axum + tera + htmx · no other javascript