Skip to main content

DeleteQuery

Struct DeleteQuery 

Source
pub struct DeleteQuery {
    pub with: With,
    pub hints: Hints,
    pub modifiers: Modifiers,
    pub tables: Vec<TableRef>,
    pub partitions: Vec<Cow<'static, str>>,
    pub using: TableRef,
    pub extra_using: Vec<TableRef>,
    pub where_: Where,
    pub order_by: OrderBy,
    pub limit: Limit,
}
Expand description

A MySQL DELETE.

From https://dev.mysql.com/doc/refman/8.4/en/delete.html, taking the single-table form and the FROM … USING spelling of the multiple-table one:

[WITH [RECURSIVE] with_query [, ...]]
DELETE [hint_comment] [LOW_PRIORITY] [QUICK] [IGNORE]
    FROM tbl_name[.*] [[AS] tbl_alias] [, tbl_name[.*]] ...
    [PARTITION (partition_name [, partition_name] ...)]
    [USING table_references]
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]

MySQL spells the multiple-table delete two ways — DELETE t1, t2 FROM refs and DELETE FROM t1, t2 USING refs. Only the second is built here, because it is also the single-table form with the USING left out, so one shape covers both and DELETE FROM t is what an empty USING gives.

§PARTITION sits in an odd place

This is the one statement where MySQL writes PARTITION after the alias. TableRef puts it before, which is right everywhere else, so HasDeleteTables carries a partition slot of its own and the delete::from(..).partition(..) chain moves its list into it.

ORDER BY and LIMIT, like in UPDATE, are single-table only.

Fields§

§with: With

WITH ….

§hints: Hints

/*+ … */.

§modifiers: Modifiers

LOW_PRIORITY, QUICK and IGNORE.

§tables: Vec<TableRef>

The tables rows are deleted from — the FROM list.

§partitions: Vec<Cow<'static, str>>

PARTITION (…), written after the FROM list.

§using: TableRef

The first USING item, with its joins.

§extra_using: Vec<TableRef>

Further comma-separated USING items.

§where_: Where

WHERE ….

§order_by: OrderBy

ORDER BY …. Single-table form only.

§limit: Limit

LIMIT row_count. Single-table form only, and there is no OFFSET.

Implementations§

Source§

impl DeleteQuery

Source

pub fn new() -> DeleteQuery

A DELETE with nothing set yet.

Source

pub fn apply(&mut self, mods: impl Mod<DeleteQuery>)

Apply more mods to an existing query.

Trait Implementations§

Source§

impl Clone for DeleteQuery

Source§

fn clone(&self) -> DeleteQuery

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DeleteQuery

Source§

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

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

impl Default for DeleteQuery

Source§

fn default() -> DeleteQuery

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

impl Expression for DeleteQuery

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Append this fragment to w. Read more
Source§

impl HasDeleteTables for DeleteQuery

Source§

fn delete_tables_mut(&mut self) -> &mut Vec<TableRef>

The tables to delete from.
Source§

fn delete_partitions_mut(&mut self) -> &mut Vec<Cow<'static, str>>

The partitions to restrict the delete to.
Source§

impl HasExtraTables for DeleteQuery

Source§

fn extra_tables_mut(&mut self) -> &mut Vec<TableRef>

The additional table references to modify.
Source§

impl HasHints for DeleteQuery

Source§

fn hints_mut(&mut self) -> &mut Hints

The hints to add to.
Source§

impl HasJoins for DeleteQuery

Source§

fn joins_mut(&mut self) -> &mut Vec<Join>

The join list to modify.
Source§

impl HasLimit for DeleteQuery

Source§

fn limit_mut(&mut self) -> &mut Limit

The LIMIT clause to modify.
Source§

impl HasModifiers for DeleteQuery

Source§

fn modifiers_mut(&mut self) -> &mut Modifiers

The modifiers to add to.
Source§

impl HasOrderBy for DeleteQuery

Source§

fn order_by_mut(&mut self) -> &mut OrderBy

The ORDER BY clause to modify.
Source§

impl HasTableRef for DeleteQuery

Source§

fn table_ref_mut(&mut self) -> &mut TableRef

The table reference to modify.
Source§

impl HasWhere for DeleteQuery

Source§

fn where_mut(&mut self) -> &mut Where

The WHERE clause to modify.
Source§

impl HasWith for DeleteQuery

Source§

fn with_mut(&mut self) -> &mut With

The WITH clause to modify.
Source§

impl IntoExpr for DeleteQuery

Source§

fn into_expr(self) -> Expr

Perform the conversion.
Source§

impl IntoExprList for DeleteQuery

Source§

fn into_expr_list(self) -> Vec<Expr>

Perform the conversion.
Source§

impl Query for DeleteQuery

Source§

fn query_type(&self) -> QueryType

Which statement this renders.
Source§

fn dialect(&self) -> &dyn Dialect

The dialect this query renders itself in. Read more
Source§

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

Render to SQL and arguments, numbering placeholders from 1. Read more
Source§

fn build_from(&self, start: usize) -> Result<(String, Vec<Value>), Error>

build with a different first placeholder position, for splicing into a statement that already has arguments — bob’s BuildN.
Source§

impl<H, L, M> QueryExtensions<H, L, M> for DeleteQuery

Source§

fn hooks(&self) -> &[Hook]

Hooks to run before this query executes.
Source§

fn loaders(&self) -> &[Loader]

Loaders to run after this query executes, for eagerly loaded relations.
Source§

fn mapper_mods(&self) -> &[MapperMod]

Adjustments to the row mapper, for relations loaded in the same query.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.