Skip to main content

UpdateStatement

Struct UpdateStatement 

Source
pub struct UpdateStatement { /* private fields */ }
Expand description

UPDATE statement builder

This struct provides a fluent API for constructing UPDATE queries.

§Examples

use reinhardt_query::prelude::*;

let query = Query::update()
    .table("users")
    .value("active", false)
    .and_where(Expr::col("last_login").lt("2020-01-01"));

Implementations§

Source§

impl UpdateStatement

Source

pub fn new() -> Self

Create a new UPDATE statement

Source

pub fn take(&mut self) -> Self

Take the ownership of data in the current UpdateStatement

Source

pub fn table<T>(&mut self, tbl: T) -> &mut Self
where T: IntoTableRef,

Set the table to update

§Examples
use reinhardt_query::prelude::*;

let query = Query::update()
    .table("users");
Source

pub fn value<C, V>(&mut self, col: C, val: V) -> &mut Self
where C: IntoIden, V: IntoValue,

Set a column value

§Examples
use reinhardt_query::prelude::*;

let query = Query::update()
    .table("users")
    .value("active", false)
    .value("name", "Alice");
Source

pub fn value_expr<C, E>(&mut self, col: C, expr: E) -> &mut Self
where C: IntoIden, E: Into<SimpleExpr>,

Set a column to an expression value

Use this method when the value is an expression (e.g., Expr::current_timestamp(), Expr::col("other_column"), Expr::cust("NULL")) rather than a plain value.

§Examples
use reinhardt_query::prelude::*;

let query = Query::update()
    .table("users")
    .value_expr("updated_at", Expr::current_timestamp())
    .value_expr("status", Expr::cust("NULL"));
Source

pub fn values<I, C, V>(&mut self, values: I) -> &mut Self
where I: IntoIterator<Item = (C, V)>, C: IntoIden, V: IntoValue,

Set multiple column values

§Examples
use reinhardt_query::prelude::*;

let query = Query::update()
    .table("users")
    .values([
        ("name", "Alice".into()),
        ("email", "alice@example.com".into()),
    ]);
Source

pub fn and_where<C>(&mut self, condition: C) -> &mut Self
where C: IntoCondition,

Add a condition to the WHERE clause

§Examples
use reinhardt_query::prelude::*;

let query = Query::update()
    .table("users")
    .value("active", false)
    .and_where(Expr::col("last_login").lt("2020-01-01"));
Source

pub fn cond_where(&mut self, condition: Condition) -> &mut Self

Add a conditional WHERE clause.

This is an alias for and_where that accepts a Condition.

Source

pub fn returning<I, C>(&mut self, cols: I) -> &mut Self
where I: IntoIterator<Item = C>, C: IntoColumnRef,

Add a RETURNING clause

§Examples
use reinhardt_query::prelude::*;

let query = Query::update()
    .table("users")
    .value("active", false)
    .and_where(Expr::col("id").eq(1))
    .returning(["id", "updated_at"]);
Source

pub fn returning_all(&mut self) -> &mut Self

Add a RETURNING * clause

§Examples
use reinhardt_query::prelude::*;

let query = Query::update()
    .table("users")
    .value("active", false)
    .and_where(Expr::col("id").eq(1))
    .returning_all();

Trait Implementations§

Source§

impl Clone for UpdateStatement

Source§

fn clone(&self) -> UpdateStatement

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 UpdateStatement

Source§

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

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

impl Default for UpdateStatement

Source§

fn default() -> Self

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

impl QueryStatementBuilder for UpdateStatement

Source§

fn build_any(&self, query_builder: &dyn QueryBuilderTrait) -> (String, Values)

Build SQL statement for a database backend and collect query parameters Read more
Source§

fn to_string<T: QueryBuilderTrait>(&self, query_builder: T) -> String

Build SQL statement for a database backend and return SQL string with values inlined as SQL literals. Read more
Source§

fn build<T: QueryBuilderTrait>(&self, query_builder: T) -> (String, Values)

Build SQL statement with parameter collection Read more
Source§

impl QueryStatementWriter for UpdateStatement

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.