Skip to main content

UpdateQuery

Struct UpdateQuery 

Source
pub struct UpdateQuery {
    pub with: With,
    pub or: Option<Or>,
    pub table: TableRef,
    pub set: Set,
    pub from: TableRef,
    pub extra_from: Vec<TableRef>,
    pub where_: Where,
    pub returning: Returning,
}
Expand description

A SQLite UPDATE.

From https://www.sqlite.org/lang_update.html:

[ WITH [ RECURSIVE ] common-table-expression [, ...] ]
UPDATE [ OR { ROLLBACK | ABORT | REPLACE | FAIL | IGNORE } ] qualified-table-name
    SET { column | ( column [, ...] ) } = expr [, ...]
    [ FROM table-or-subquery [, ...] | join-clause ]
    [ WHERE expr ]
    [ RETURNING result-column [, ...] ]

UPDATE … FROM needs SQLite 3.33 or later and RETURNING needs 3.35.

The target is a qualified-table-name, so it takes INDEXED BY/NOT INDEXED but not a column-alias list — the alias list SQLite allows there is only AS alias. The FROM items are table-or-subquerys and the joins attach to those, never to the target, which is the whole reason table and from are different mods.

The assignment list is not optional: UPDATE t with no SET is not a statement, so an empty Set is a recorded Error::Incomplete.

There is no ORDER BY or LIMIT here. SQLite’s parser accepts them, but only a build compiled with SQLITE_ENABLE_UPDATE_DELETE_LIMIT does, and the ordinary one refuses them.

Fields§

§with: With

WITH ….

§or: Option<Or>

OR REPLACE and friends. None is the default, ABORT.

§table: TableRef

The table being updated.

§set: Set

SET ….

§from: TableRef

The first FROM item, with its joins.

§extra_from: Vec<TableRef>

Further comma-separated FROM items.

§where_: Where

WHERE ….

§returning: Returning

RETURNING ….

Implementations§

Source§

impl UpdateQuery

Source

pub fn new() -> UpdateQuery

An UPDATE with nothing set yet.

Source

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

Apply more mods to an existing query.

Trait Implementations§

Source§

impl Clone for UpdateQuery

Source§

fn clone(&self) -> UpdateQuery

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 UpdateQuery

Source§

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

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

impl Default for UpdateQuery

Source§

fn default() -> UpdateQuery

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

impl Expression for UpdateQuery

Source§

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

Append this fragment to w. Read more
Source§

impl HasExtraTables for UpdateQuery

Source§

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

The additional from-items to modify.
Source§

impl HasJoins for UpdateQuery

Source§

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

The join list to modify.
Source§

impl HasOr for UpdateQuery

Source§

fn or_mut(&mut self) -> &mut Option<Or>

The conflict algorithm to modify.
Source§

impl HasReturning for UpdateQuery

Source§

fn returning_mut(&mut self) -> &mut Returning

The RETURNING clause to modify.
Source§

impl HasSet for UpdateQuery

Source§

fn set_mut(&mut self) -> &mut Set

The assignment list to modify.
Source§

impl HasTableRef for UpdateQuery

Source§

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

The table reference to modify.
Source§

impl HasTargetTable for UpdateQuery

Source§

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

The target table to modify.
Source§

impl HasWhere for UpdateQuery

Source§

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

The WHERE clause to modify.
Source§

impl HasWith for UpdateQuery

Source§

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

The WITH clause to modify.
Source§

impl IntoExpr for UpdateQuery

Source§

fn into_expr(self) -> Expr

Perform the conversion.
Source§

impl IntoExprList for UpdateQuery

Source§

fn into_expr_list(self) -> Vec<Expr>

Perform the conversion.
Source§

impl Query for UpdateQuery

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 UpdateQuery

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.