rent
Learn by example

9. Pessimistic row locking

Optimistic locking detects a conflict after it happens. Row locking prevents another transaction from acquiring the same lock while the first workflow decides what to do.

let locked = Select::new(
    Dialect::Postgres,
    TableRef::new("posts"),
    ["id", "version"],
)
    .lock(
        LockClause::new(LockStrength::Update)
            .tables(["posts"])
            .wait(LockWait::NoWait),
    );

locked.validate()?;

Rent rejects row-lock clauses for SQLite rather than silently dropping them. The participating Post fields are in crates/rent/examples/tutorial_08_row_locking/schema.rsl. Run cargo run -p rent --example tutorial_08_row_locking; the same backend-capability check runs under nextest.