Skip to main content

DeleteBuilder

Struct DeleteBuilder 

Source
pub struct DeleteBuilder<'a, M: Model> { /* private fields */ }
Expand description

DELETE query builder.

§Example

// Delete by filter
delete!(Hero)
    .filter(Expr::col("age").lt(18))
    .execute(cx, &conn).await?;

// Delete a specific model instance
DeleteBuilder::from_model(&hero)
    .execute(cx, &conn).await?;

// Delete with RETURNING
let rows = delete!(Hero)
    .filter(Expr::col("status").eq("inactive"))
    .returning()
    .execute_returning(cx, &conn).await?;

Implementations§

Source§

impl<'a, M: Model> DeleteBuilder<'a, M>

Source

pub fn new() -> Self

Create a new DELETE builder for the model type.

Source

pub fn from_model(model: &'a M) -> Self

Create a DELETE builder for a specific model instance.

This automatically adds a WHERE clause matching the primary key.

Source

pub fn filter(self, expr: Expr) -> Self

Add a WHERE condition.

Source

pub fn returning(self) -> Self

Add RETURNING * clause to return the deleted row(s).

Source

pub fn build(&self) -> (String, Vec<Value>)

Build the DELETE SQL and parameters with default dialect (Postgres).

Source

pub fn build_with_dialect(&self, dialect: Dialect) -> (String, Vec<Value>)

Build the DELETE SQL and parameters with specific dialect.

Source

pub async fn execute<C: Connection>( self, cx: &Cx, conn: &C, ) -> Outcome<u64, Error>

Execute the DELETE and return rows affected.

Joined-table inheritance semantics:

  • Filters select target child primary keys from a base+child join.
  • Deletion always removes matching child rows and their parent rows in one transaction.
Source

pub async fn execute_returning<C: Connection>( self, cx: &Cx, conn: &C, ) -> Outcome<Vec<Row>, Error>

Execute the DELETE with RETURNING and get the deleted rows.

For joined-table inheritance child models, returned rows are projected with both child and parent prefixes (table__column) before the delete is applied.

Trait Implementations§

Source§

impl<'a, M: Debug + Model> Debug for DeleteBuilder<'a, M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M: Model> Default for DeleteBuilder<'_, M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a, M> Freeze for DeleteBuilder<'a, M>

§

impl<'a, M> RefUnwindSafe for DeleteBuilder<'a, M>
where M: RefUnwindSafe,

§

impl<'a, M> Send for DeleteBuilder<'a, M>

§

impl<'a, M> Sync for DeleteBuilder<'a, M>

§

impl<'a, M> Unpin for DeleteBuilder<'a, M>
where M: Unpin,

§

impl<'a, M> UnwindSafe for DeleteBuilder<'a, M>

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: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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