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>
impl<'a, M: Model> DeleteBuilder<'a, M>
Sourcepub fn from_model(model: &'a M) -> Self
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.
Sourcepub fn build(&self) -> (String, Vec<Value>)
pub fn build(&self) -> (String, Vec<Value>)
Build the DELETE SQL and parameters with default dialect (Postgres).
Sourcepub fn build_with_dialect(&self, dialect: Dialect) -> (String, Vec<Value>)
pub fn build_with_dialect(&self, dialect: Dialect) -> (String, Vec<Value>)
Build the DELETE SQL and parameters with specific dialect.
Sourcepub async fn execute<C: Connection>(
self,
cx: &Cx,
conn: &C,
) -> Outcome<u64, Error>
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.
Sourcepub async fn execute_returning<C: Connection>(
self,
cx: &Cx,
conn: &C,
) -> Outcome<Vec<Row>, Error>
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§
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>where
M: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).