Function diesel::delete

source · []
pub fn delete<T: IntoUpdateTarget>(
    source: T
) -> DeleteStatement<T::Table, T::WhereClause>
Expand description

Creates a DELETE statement.

When a table is passed to delete, every row in the table will be deleted. This scope can be narrowed by calling filter on the table before it is passed in.

Examples

Deleting a single record:

let old_count = get_count();
diesel::delete(users.filter(id.eq(1))).execute(&connection)?;
assert_eq!(old_count.map(|count| count - 1), get_count());

Deleting a whole table:

diesel::delete(users).execute(&connection)?;
assert_eq!(Ok(0), get_count());