Skip to main content

Delete

Struct Delete 

Source
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>

Source

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>

Source

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,

Source

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();

Trait Implementations§

Source§

impl<T> From<Delete<T>> for Statement<T>

Source§

fn from(value: Delete<T>) -> Statement<T>

Converts to this type from the input type.
Source§

impl<T> IntoStatement for Delete<T>

Source§

type Returning = T

The type this statement produces when executed.
Source§

fn into_statement(self) -> Statement<T>

Consume self and produce the Statement.

Auto Trait Implementations§

§

impl<T> Freeze for Delete<T>
where PhantomData<T>: Freeze,

§

impl<T> RefUnwindSafe for Delete<T>

§

impl<T> Send for Delete<T>
where PhantomData<T>: Send,

§

impl<T> Sync for Delete<T>
where PhantomData<T>: Sync,

§

impl<T> Unpin for Delete<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for Delete<T>

§

impl<T> UnwindSafe for Delete<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more