Function diesel::update [] [src]

pub fn update<T: IntoUpdateTarget>(
    source: T
) -> IncompleteUpdateStatement<T::Table, T::WhereClause>

Creates an UPDATE statement. Helpers for updating a single row can be generated by deriving AsChangeset

When a table is passed to update, every row in the table will be updated. You can narrow this scope by calling filter on the table before passing it in, which will result in UPDATE your_table SET ... WHERE args_to_filter.

Passing a type which implements Identifiable is the same as passing some_table.find(


let updated_row = diesel::update(users.filter(id.eq(1)))
// On backends that support it, you can call `get_result` instead of `execute`
// to have `RETURNING *` automatically appended to the query. Alternatively, you
// can explicitly return an expression by using the `returning` method before
// getting the result.
assert_eq!(Ok((1, "James".to_string())), updated_row);

To update multiple columns, give set a tuple argument:

let updated_row = diesel::update(users.filter(id.eq(1)))
    .set((name.eq("James"), surname.eq("Bond")))

assert_eq!(Ok((1, "James".to_string(), "Bond".to_string())), updated_row);