Macro rorm::delete

source ·
macro_rules! delete {
    ($db:expr, $model:path) => { ... };
}
Expand description

Create a DELETE query.

Usage

pub async fn delete_single_user(db: &Database, user: &UserPatch) {
    delete!(db, User)
        .single(user)
        .await
        .unwrap();
}
pub async fn delete_many_users(db: &Database, users: &[UserPatch]) {
    delete!(db, User)
        .bulk(users)
        .await
        .unwrap();
}
pub async fn delete_underage(db: &Database) {
    let num_deleted: u64 = delete!(db, User)
        .condition(User::F.age.less_equals(18))
        .await
        .unwrap();
}

Like every crud macro delete! starts a builder which is consumed to execute the query.

delete!’s first argument is a reference to the Database. Its second is the Model type of whose table you want to delete columns from.

To specify what rows to delete use the following methods, which will consume the builder and execute the query:

  • single: Delete a single row identified by a patch instance
  • bulk: Delete a bulk of rows identified by patch instances
  • condition: Delete all rows matching a condition
  • all: Unconditionally delete all rows