pub struct UpdateStatement { /* private fields */ }
Expand description
Update existing rows in the table
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::update()
.table(Glyph::Table)
.values([(Glyph::Aspect, 1.23.into()), (Glyph::Image, "123".into())])
.and_where(Expr::col(Glyph::Id).eq(1))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"UPDATE `glyph` SET `aspect` = 1.23, `image` = '123' WHERE `id` = 1"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 1.23, "image" = '123' WHERE "id" = 1"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 1.23, "image" = '123' WHERE "id" = 1"#
);
Implementationsยง
sourceยงimpl UpdateStatement
impl UpdateStatement
sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new UpdateStatement
sourcepub fn table<T>(&mut self, tbl_ref: T) -> &mut Selfwhere
T: IntoTableRef,
pub fn table<T>(&mut self, tbl_ref: T) -> &mut Selfwhere
T: IntoTableRef,
sourcepub fn values<T, I>(&mut self, values: I) -> &mut Self
pub fn values<T, I>(&mut self, values: I) -> &mut Self
Update column values. To set multiple column-value pairs at once.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::update()
.table(Glyph::Table)
.values([
(Glyph::Aspect, 2.1345.into()),
(Glyph::Image, "235m".into()),
])
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m'"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m'"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m'"#
);
sourcepub fn value<C, T>(&mut self, col: C, value: T) -> &mut Self
pub fn value<C, T>(&mut self, col: C, value: T) -> &mut Self
Update column value by SimpleExpr
.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::update()
.table(Glyph::Table)
.value(Glyph::Aspect, Expr::cust("60 * 24 * 24"))
.values([
(Glyph::Image, "24B0E11951B03B07F8300FD003983F03F0780060".into()),
])
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"UPDATE `glyph` SET `aspect` = 60 * 24 * 24, `image` = '24B0E11951B03B07F8300FD003983F03F0780060'"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 60 * 24 * 24, "image" = '24B0E11951B03B07F8300FD003983F03F0780060'"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 60 * 24 * 24, "image" = '24B0E11951B03B07F8300FD003983F03F0780060'"#
);
sourcepub fn returning(&mut self, returning: ReturningClause) -> &mut Self
pub fn returning(&mut self, returning: ReturningClause) -> &mut Self
RETURNING expressions.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::update()
.table(Glyph::Table)
.value(Glyph::Aspect, 2.1345)
.value(Glyph::Image, "235m")
.returning(Query::returning().columns([Glyph::Id]))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m'"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING "id""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING "id""#
);
sourcepub fn returning_col<C>(&mut self, col: C) -> &mut Selfwhere
C: IntoColumnRef,
pub fn returning_col<C>(&mut self, col: C) -> &mut Selfwhere
C: IntoColumnRef,
RETURNING expressions for a column.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::update()
.table(Glyph::Table)
.table(Glyph::Table)
.value(Glyph::Aspect, 2.1345)
.value(Glyph::Image, "235m")
.returning_col(Glyph::Id)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m'"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING "id""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING "id""#
);
sourcepub fn returning_all(&mut self) -> &mut Self
pub fn returning_all(&mut self) -> &mut Self
RETURNING expressions all columns.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::update()
.table(Glyph::Table)
.table(Glyph::Table)
.value(Glyph::Aspect, 2.1345)
.value(Glyph::Image, "235m")
.returning_all()
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m'"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING *"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING *"#
);
sourcepub fn with(self, clause: WithClause) -> WithQuery
pub fn with(self, clause: WithClause) -> WithQuery
Create a WithQuery by specifying a WithClause to execute this query with.
ยงExamples
use sea_query::{*, IntoCondition, IntoIden, tests_cfg::*};
let select = SelectStatement::new()
.columns([Glyph::Id])
.from(Glyph::Table)
.and_where(Expr::col(Glyph::Image).like("0%"))
.to_owned();
let cte = CommonTableExpression::new()
.query(select)
.column(Glyph::Id)
.table_name(Alias::new("cte"))
.to_owned();
let with_clause = WithClause::new().cte(cte).to_owned();
let update = UpdateStatement::new()
.table(Glyph::Table)
.and_where(Expr::col(Glyph::Id).in_subquery(SelectStatement::new().column(Glyph::Id).from(Alias::new("cte")).to_owned()))
.value(Glyph::Aspect, Expr::cust("60 * 24 * 24"))
.to_owned();
let query = update.with(with_clause);
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"WITH `cte` (`id`) AS (SELECT `id` FROM `glyph` WHERE `image` LIKE '0%') UPDATE `glyph` SET `aspect` = 60 * 24 * 24 WHERE `id` IN (SELECT `id` FROM `cte`)"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"WITH "cte" ("id") AS (SELECT "id" FROM "glyph" WHERE "image" LIKE '0%') UPDATE "glyph" SET "aspect" = 60 * 24 * 24 WHERE "id" IN (SELECT "id" FROM "cte")"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"WITH "cte" ("id") AS (SELECT "id" FROM "glyph" WHERE "image" LIKE '0%') UPDATE "glyph" SET "aspect" = 60 * 24 * 24 WHERE "id" IN (SELECT "id" FROM "cte")"#
);
sourcepub fn get_values(&self) -> &[(DynIden, Box<SimpleExpr>)]
pub fn get_values(&self) -> &[(DynIden, Box<SimpleExpr>)]
Get column values
sourceยงimpl UpdateStatement
impl UpdateStatement
sourcepub fn build_collect_any_into(
&self,
query_builder: &dyn QueryBuilder,
sql: &mut dyn SqlWriter,
)
pub fn build_collect_any_into( &self, query_builder: &dyn QueryBuilder, sql: &mut dyn SqlWriter, )
sourcepub fn into_sub_query_statement(self) -> SubQueryStatement
pub fn into_sub_query_statement(self) -> SubQueryStatement
sourcepub fn build_any(&self, query_builder: &dyn QueryBuilder) -> (String, Values)
pub fn build_any(&self, query_builder: &dyn QueryBuilder) -> (String, Values)
sourcepub fn build_collect_any(
&self,
query_builder: &dyn QueryBuilder,
sql: &mut dyn SqlWriter,
) -> String
pub fn build_collect_any( &self, query_builder: &dyn QueryBuilder, sql: &mut dyn SqlWriter, ) -> String
sourceยงimpl UpdateStatement
impl UpdateStatement
sourcepub fn build_collect_into<T: QueryBuilder>(
&self,
query_builder: T,
sql: &mut dyn SqlWriter,
)
pub fn build_collect_into<T: QueryBuilder>( &self, query_builder: T, sql: &mut dyn SqlWriter, )
sourcepub fn build_collect<T: QueryBuilder>(
&self,
query_builder: T,
sql: &mut dyn SqlWriter,
) -> String
pub fn build_collect<T: QueryBuilder>( &self, query_builder: T, sql: &mut dyn SqlWriter, ) -> String
sourcepub fn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
pub fn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
sourcepub fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
pub fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
sourceยงimpl UpdateStatement
impl UpdateStatement
sourcepub fn add_order_by(&mut self, order: OrderExpr) -> &mut Self
pub fn add_order_by(&mut self, order: OrderExpr) -> &mut Self
sourcepub fn clear_order_by(&mut self) -> &mut Self
pub fn clear_order_by(&mut self) -> &mut Self
sourcepub fn order_by<T>(&mut self, col: T, order: Order) -> &mut Selfwhere
T: IntoColumnRef,
pub fn order_by<T>(&mut self, col: T, order: Order) -> &mut Selfwhere
T: IntoColumnRef,
sourcepub fn order_by_expr(&mut self, expr: SimpleExpr, order: Order) -> &mut Self
pub fn order_by_expr(&mut self, expr: SimpleExpr, order: Order) -> &mut Self
sourcepub fn order_by_customs<I, T>(&mut self, cols: I) -> &mut Self
pub fn order_by_customs<I, T>(&mut self, cols: I) -> &mut Self
sourcepub fn order_by_columns<I, T>(&mut self, cols: I) -> &mut Self
pub fn order_by_columns<I, T>(&mut self, cols: I) -> &mut Self
sourcepub fn order_by_with_nulls<T>(
&mut self,
col: T,
order: Order,
nulls: NullOrdering,
) -> &mut Selfwhere
T: IntoColumnRef,
pub fn order_by_with_nulls<T>(
&mut self,
col: T,
order: Order,
nulls: NullOrdering,
) -> &mut Selfwhere
T: IntoColumnRef,
sourcepub fn order_by_expr_with_nulls(
&mut self,
expr: SimpleExpr,
order: Order,
nulls: NullOrdering,
) -> &mut Self
pub fn order_by_expr_with_nulls( &mut self, expr: SimpleExpr, order: Order, nulls: NullOrdering, ) -> &mut Self
sourcepub fn order_by_customs_with_nulls<I, T>(&mut self, cols: I) -> &mut Self
pub fn order_by_customs_with_nulls<I, T>(&mut self, cols: I) -> &mut Self
sourcepub fn order_by_columns_with_nulls<I, T>(&mut self, cols: I) -> &mut Self
pub fn order_by_columns_with_nulls<I, T>(&mut self, cols: I) -> &mut Self
sourceยงimpl UpdateStatement
impl UpdateStatement
sourcepub fn and_or_where(&mut self, condition: LogicalChainOper) -> &mut Self
pub fn and_or_where(&mut self, condition: LogicalChainOper) -> &mut Self
sourcepub fn cond_where<C>(&mut self, condition: C) -> &mut Selfwhere
C: IntoCondition,
pub fn cond_where<C>(&mut self, condition: C) -> &mut Selfwhere
C: IntoCondition,
sourcepub fn and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self
pub fn and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self
sourcepub fn and_where(&mut self, other: SimpleExpr) -> &mut Self
pub fn and_where(&mut self, other: SimpleExpr) -> &mut Self
Trait Implementationsยง
sourceยงimpl Clone for UpdateStatement
impl Clone for UpdateStatement
sourceยงfn clone(&self) -> UpdateStatement
fn clone(&self) -> UpdateStatement
Returns a copy of the value. Read more
1.0.0 ยท sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceยงimpl ConditionalStatement for UpdateStatement
impl ConditionalStatement for UpdateStatement
sourceยงfn cond_where<C>(&mut self, condition: C) -> &mut Selfwhere
C: IntoCondition,
fn cond_where<C>(&mut self, condition: C) -> &mut Selfwhere
C: IntoCondition,
Where condition, expressed with
any
and all
.
Calling cond_where
multiple times will conjoin them.
Calling or_where
after cond_where
will panic. Read moresourceยงfn and_where(&mut self, other: SimpleExpr) -> &mut Self
fn and_where(&mut self, other: SimpleExpr) -> &mut Self
sourceยงfn and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self
fn and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self
Optional and where, short hand for
if c.is_some() q.and_where(c)
. Read moresourceยงimpl Debug for UpdateStatement
impl Debug for UpdateStatement
sourceยงimpl Default for UpdateStatement
impl Default for UpdateStatement
sourceยงfn default() -> UpdateStatement
fn default() -> UpdateStatement
Returns the โdefault valueโ for a type. Read more
sourceยงimpl OrderedStatement for UpdateStatement
impl OrderedStatement for UpdateStatement
sourceยงfn clear_order_by(&mut self) -> &mut Self
fn clear_order_by(&mut self) -> &mut Self
Clear order expressions
sourceยงfn order_by<T>(&mut self, col: T, order: Order) -> &mut Selfwhere
T: IntoColumnRef,
fn order_by<T>(&mut self, col: T, order: Order) -> &mut Selfwhere
T: IntoColumnRef,
Order by column. Read more
sourceยงfn order_by_expr(&mut self, expr: SimpleExpr, order: Order) -> &mut Self
fn order_by_expr(&mut self, expr: SimpleExpr, order: Order) -> &mut Self
Order by
SimpleExpr
.sourceยงfn order_by_customs<I, T>(&mut self, cols: I) -> &mut Self
fn order_by_customs<I, T>(&mut self, cols: I) -> &mut Self
Order by custom string.
sourceยงfn order_by_columns<I, T>(&mut self, cols: I) -> &mut Self
fn order_by_columns<I, T>(&mut self, cols: I) -> &mut Self
Order by vector of columns.
sourceยงfn order_by_with_nulls<T>(
&mut self,
col: T,
order: Order,
nulls: NullOrdering,
) -> &mut Selfwhere
T: IntoColumnRef,
fn order_by_with_nulls<T>(
&mut self,
col: T,
order: Order,
nulls: NullOrdering,
) -> &mut Selfwhere
T: IntoColumnRef,
Order by column with nulls order option. Read more
sourceยงfn order_by_expr_with_nulls(
&mut self,
expr: SimpleExpr,
order: Order,
nulls: NullOrdering,
) -> &mut Self
fn order_by_expr_with_nulls( &mut self, expr: SimpleExpr, order: Order, nulls: NullOrdering, ) -> &mut Self
Order by
SimpleExpr
with nulls order option.sourceยงfn order_by_customs_with_nulls<I, T>(&mut self, cols: I) -> &mut Self
fn order_by_customs_with_nulls<I, T>(&mut self, cols: I) -> &mut Self
Order by custom string with nulls order option.
sourceยงfn order_by_columns_with_nulls<I, T>(&mut self, cols: I) -> &mut Self
fn order_by_columns_with_nulls<I, T>(&mut self, cols: I) -> &mut Self
Order by vector of columns with nulls order option.
sourceยงimpl PartialEq for UpdateStatement
impl PartialEq for UpdateStatement
sourceยงimpl QueryStatementBuilder for UpdateStatement
impl QueryStatementBuilder for UpdateStatement
sourceยงfn build_collect_any_into(
&self,
query_builder: &dyn QueryBuilder,
sql: &mut dyn SqlWriter,
)
fn build_collect_any_into( &self, query_builder: &dyn QueryBuilder, sql: &mut dyn SqlWriter, )
Build corresponding SQL statement into the SqlWriter for certain database backend and collect query parameters
fn into_sub_query_statement(self) -> SubQueryStatement
sourceยงfn build_any(&self, query_builder: &dyn QueryBuilder) -> (String, Values)
fn build_any(&self, query_builder: &dyn QueryBuilder) -> (String, Values)
Build corresponding SQL statement for certain database backend and collect query parameters into a vector
sourceยงfn build_collect_any(
&self,
query_builder: &dyn QueryBuilder,
sql: &mut dyn SqlWriter,
) -> String
fn build_collect_any( &self, query_builder: &dyn QueryBuilder, sql: &mut dyn SqlWriter, ) -> String
Build corresponding SQL statement for certain database backend and collect query parameters
sourceยงimpl QueryStatementWriter for UpdateStatement
impl QueryStatementWriter for UpdateStatement
fn build_collect_into<T: QueryBuilder>( &self, query_builder: T, sql: &mut dyn SqlWriter, )
sourceยงfn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
Build corresponding SQL statement for certain database backend and return SQL string Read more
sourceยงfn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
fn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
Build corresponding SQL statement for certain database backend and collect query parameters into a vector Read more
sourceยงfn build_collect<T: QueryBuilder>(
&self,
query_builder: T,
sql: &mut dyn SqlWriter,
) -> String
fn build_collect<T: QueryBuilder>( &self, query_builder: T, sql: &mut dyn SqlWriter, ) -> String
Build corresponding SQL statement for certain database backend and collect query parameters Read more
impl StructuralPartialEq for UpdateStatement
Auto Trait Implementationsยง
impl Freeze for UpdateStatement
impl !RefUnwindSafe for UpdateStatement
impl Send for UpdateStatement
impl Sync for UpdateStatement
impl Unpin for UpdateStatement
impl !UnwindSafe for UpdateStatement
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
sourceยงunsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
๐ฌThis is a nightly-only experimental API. (
clone_to_uninit
)