Skip to main content

add

Function add 

Source
pub fn add<T>(value: impl IntoExpr<T>) -> Assignment<T>
where T: Numeric,
Expand description

Add a value to a numeric field (col = col + value).

The Numeric bound restricts T to types Toasty knows how to do database arithmetic on, so misuse on a non-numeric column (e.g. String) is a compile error rather than a runtime database error.

The update is atomic against the existing column value on every backend. Use this when you want a relative update โ€” e.g. crediting a balance โ€” without a read-modify-write round trip from the client.

ยงExamples

โ“˜
user.update()
    .balance(stmt::add(10))
    .exec(&mut db)
    .await?;