rent
Concepts

Optimistic locking

Declare one version field:

version UInt @rent.version

Entity-targeted updates automatically compare and increment it:

let updated = client
    .update_document_one(&document)
    .contents("new text")
    .save_one()
    .await?;

assert_eq!(updated.version, document.version + 1);

The generated SQL includes both the ID and old version in its predicate, and increments the version in the same update. A stale write returns EntityError::OptimisticLock rather than an affected-row count of zero.

When only an ID and version are available:

client
    .update_document()
    .one(document_id)
    .expect_version(read_version)
    .contents("new text")
    .save()
    .await?;