Expand description
§ferro-orm
Atomic conditional updates and ORM primitives for the Ferro framework.
GuardedUpdate<E> compiles to a single UPDATE … WHERE … SQL statement,
replacing the hand-rolled read → check → write pattern wherever a column’s
value is conditionally mutated. The database is the authority on contention;
the call site is race-free by construction.
§Example
ⓘ
use ferro_orm::{GuardedUpdate, ColumnTrait};
use sea_orm::sea_query::Expr;
GuardedUpdate::new(inventory_units::Entity)
.filter(inventory_units::Column::Id.eq(unit_id))
.filter(inventory_units::Column::Quantity.gte(needed))
.set_expr(
inventory_units::Column::Quantity,
Expr::col(inventory_units::Column::Quantity).sub(needed),
)
.exec_one(&txn)
.await?;
// — exactly one row matched and was decremented atomically,
// OR Err(NoRowsAffected) signalling capacity exhausted.§Atomicity guarantee (and its limit)
GuardedUpdate guarantees atomicity per statement, not per builder.
A caller building .set_expr(qty - 1) and reading the resulting qty
in a separate query without a transaction re-introduces a race. The crate’s
job is to make the conditional UPDATE race-free; bracketing it in a
transaction is the caller’s responsibility.
Structs§
- Expr
- Helper to build a
SimpleExpr. - Guarded
Update
Enums§
- DbErr
- An error from unsuccessful database operations
- Guarded
Error - Simple
Expr - Represents a Simple Expression in SQL.
- Value
- Value variants
Traits§
- Column
Trait - API for working with a
Column. Mostly a wrapper of the identically named methods insea_query::Expr - Connection
Trait - The generic API for a database connection that can perform query or execute statements. It abstracts database connection and transaction
- Entity
Trait - An abstract base class for defining Entities.
- Into
Condition