rent
Learn by example

2. Your first entity

Start with one User and an in-memory SQLite database. Rent generates a Rust client from the RSL schema; your application gets typed builders instead of stringly table and column names.

let ada = client
    .create_user_from(NewUser {
        name: "Ada".to_owned(),
    })
    .id(1)
    .save()
    .await?;

let ada = client.user().id_eq(ada.id).only().await?;

let ada = client
    .update_user_one(&ada)
    .name("Ada Lovelace")
    .save_one()
    .await?;

client.delete_user_one(&ada).exec().await?;

NewUser is generated from required create fields, so the compiler points out a missing required value before the query runs. For conditional or progressively assembled input, use the fluent create_user() builder instead.

only() requires exactly one row. Use only_or_none() for optional lookup and all() for a collection. Mutation builders do nothing until save(), save_one(), or exec() is awaited.

Run the tested chapter:

cargo run -p rent --example tutorial_01_crud

The complete one-model schema is crates/rent/examples/tutorial_01_crud/schema.rsl. The embedded nextest test calls the same exercise() function as main, so documentation behavior and test behavior cannot diverge.