pub struct Delete<T> { /* private fields */ }Expand description
A typed delete statement.
Delete<T> removes records that match the selection built by the
originating [Query]. Obtain one by calling [Query::delete].
The type parameter T is the returning type, not the model being
deleted. Currently Query::delete always produces Delete<()> because
deletes do not return the removed records.
§Execution
Call exec to run the delete, or convert it into a
Statement with IntoStatement for batch execution.
use toasty::stmt::{List, Query};
Query::<List<User>>::all().filter(User::fields().id().eq(1))
.delete()
.exec(&mut db)
.await
.unwrap();Implementations§
Source§impl<T> Delete<T>
impl<T> Delete<T>
Sourcepub const fn from_untyped(untyped: Delete) -> Delete<T>
pub const fn from_untyped(untyped: Delete) -> Delete<T>
Wrap a raw untyped stmt::Delete.
§Examples
use toasty::stmt::{Delete, List, Query};
// Build a delete from a query
let delete: Delete<()> = Query::<List<User>>::all().delete();Source§impl<T> Delete<T>
impl<T> Delete<T>
Sourcepub fn set_condition(self, condition: Condition) -> Delete<T>
pub fn set_condition(self, condition: Condition) -> Delete<T>
Attach a condition to this delete. The condition is evaluated after the filter; if it fails, the operation returns an error (unlike a filter failure, which silently produces count 0).
Source§impl<T> Delete<T>where
T: Load,
impl<T> Delete<T>where
T: Load,
Sourcepub async fn exec(
self,
executor: &mut dyn Executor,
) -> Result<<T as Load>::Output, Error>
pub async fn exec( self, executor: &mut dyn Executor, ) -> Result<<T as Load>::Output, Error>
Execute this delete statement against the given executor.
Returns Ok(()) on success. Any matching records are removed from the
database.
§Examples
User::filter(User::fields().id().eq(1))
.delete()
.exec(&mut db)
.await
.unwrap();