Skip to main content

ModelDelete

Trait ModelDelete 

Source
pub trait ModelDelete: Model {
    // Required method
    fn delete(conn: &mut SqliteConnection, id: &Self::Id) -> QueryResult<usize>;

    // Provided method
    fn delete_all(
        conn: &mut SqliteConnection,
        ids: Vec<&Self::Id>,
    ) -> QueryResult<usize> { ... }
}
Expand description

A trait for models that support deletion operations.

This trait extends the Model trait and provides methods for deleting individual and multiple records.

§Methods

  • delete: Deletes a record from the database table.
  • delete_all: Deletes multiple records from the database table.

Required Methods§

Source

fn delete(conn: &mut SqliteConnection, id: &Self::Id) -> QueryResult<usize>

Deletes a record from the database table.

§Arguments
  • conn: A mutable reference to the database connection.
  • id: A reference to the ID of the record to delete.
§Returns

A QueryResult containing the number of rows affected.

Provided Methods§

Source

fn delete_all( conn: &mut SqliteConnection, ids: Vec<&Self::Id>, ) -> QueryResult<usize>

Deletes multiple records from the database table.

Delete in input order within one transaction. A failure rolls back the entire batch. Tree models override this to handle overlapping subtrees without deleting twice.

§Arguments
  • conn: A mutable reference to the database connection.
  • ids: A vector of references to the IDs of the records to delete.
§Returns

A QueryResult containing the total number of rows affected.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§