Function diesel::dsl::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 = users.count().first::<i64>(connection);
diesel::delete(users.filter(id.eq(1))).execute(connection)?;
assert_eq!(old_count.map(|count| count - 1), users.count().first(connection));

§Deleting a whole table:

diesel::delete(users).execute(connection)?;
assert_eq!(Ok(0), users.count().first::<i64>(connection));