Struct sea_query::query::UpdateStatement [−][src]
Update existing rows in the table
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::update() .table(Glyph::Table) .values(vec![ (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
impl UpdateStatement
[src]
pub fn new() -> Self
[src]
Construct a new UpdateStatement
pub fn table<T: 'static>(&mut self, table: T) -> &mut Self where
T: Iden,
[src]
T: Iden,
pub fn table_dyn(&mut self, table: Rc<dyn Iden>) -> &mut Self
[src]
Specify which table to update, variation of UpdateStatement::table
.
Examples
pub fn into_table<T: 'static>(&mut self, table: T) -> &mut Self where
T: Iden,
[src]
T: Iden,
Please use the UpdateStatement::table function instead
pub fn into_table_dyn(&mut self, table: Rc<dyn Iden>) -> &mut Self
[src]
Please use the UpdateStatement::table_dyn function instead
pub fn value_expr<T: 'static>(&mut self, col: T, exp: SimpleExpr) -> &mut Self where
T: Iden,
[src]
T: Iden,
Update column value by SimpleExpr
.
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::update() .table(Glyph::Table) .value_expr(Glyph::Aspect, Expr::cust("60 * 24 * 24")) .values(vec![ (Glyph::Image, "24B0E11951B03B07F8300FD003983F03F0780060".into()), ]) .and_where(Expr::col(Glyph::Id).eq(1)) .to_owned(); assert_eq!( query.to_string(MysqlQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 60 * 24 * 24, `image` = '24B0E11951B03B07F8300FD003983F03F0780060' WHERE `id` = 1"# ); assert_eq!( query.to_string(PostgresQueryBuilder), r#"UPDATE "glyph" SET "aspect" = 60 * 24 * 24, "image" = '24B0E11951B03B07F8300FD003983F03F0780060' WHERE "id" = 1"# ); assert_eq!( query.to_string(SqliteQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 60 * 24 * 24, `image` = '24B0E11951B03B07F8300FD003983F03F0780060' WHERE `id` = 1"# );
pub fn value_expr_dyn(
&mut self,
col: Rc<dyn Iden>,
exp: SimpleExpr
) -> &mut Self
[src]
&mut self,
col: Rc<dyn Iden>,
exp: SimpleExpr
) -> &mut Self
Update column value by SimpleExpr
, variation of UpdateStatement::value_expr
.
pub fn json(&mut self, values: JsonValue) -> &mut Self
[src]
with-json
only.Update column values by JsonValue
. A convenience method if you have multiple column-value pairs to set at once.
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::update() .table(Glyph::Table) .json(json!({ "aspect": 2.1345, "image": "235m", })) .and_where(Expr::col(Glyph::Id).eq(1)) .to_owned(); assert_eq!( query.to_string(MysqlQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE `id` = 1"# ); assert_eq!( query.to_string(PostgresQueryBuilder), r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' WHERE "id" = 1"# ); assert_eq!( query.to_string(SqliteQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE `id` = 1"# );
pub fn values<T: 'static>(&mut self, values: Vec<(T, Value)>) -> &mut Self where
T: Iden,
[src]
T: Iden,
Update column values.. A convenience method if you have multiple column-value pairs to set at once.
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::update() .table(Glyph::Table) .values(vec![ (Glyph::Aspect, 2.1345.into()), (Glyph::Image, "235m".into()), ]) .and_where(Expr::col(Glyph::Id).eq(1)) .to_owned(); assert_eq!( query.to_string(MysqlQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE `id` = 1"# ); assert_eq!( query.to_string(PostgresQueryBuilder), r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' WHERE "id" = 1"# ); assert_eq!( query.to_string(SqliteQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE `id` = 1"# );
pub fn values_dyn(&mut self, values: Vec<(Rc<dyn Iden>, Value)>) -> &mut Self
[src]
Update column values, variation of UpdateStatement::values
.
pub fn value<T: 'static>(&mut self, col: T, value: Value) -> &mut Self where
T: Iden,
[src]
T: Iden,
Update column values.
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::update() .table(Glyph::Table) .value(Glyph::Aspect, 2.1345.into()) .value(Glyph::Image, "235m".into()) .and_where(Expr::col(Glyph::Id).eq(1)) .to_owned(); assert_eq!( query.to_string(MysqlQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE `id` = 1"# ); assert_eq!( query.to_string(PostgresQueryBuilder), r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' WHERE "id" = 1"# ); assert_eq!( query.to_string(SqliteQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE `id` = 1"# );
pub fn value_dyn(&mut self, col: Rc<dyn Iden>, value: Value) -> &mut Self
[src]
Update column values, variation of UpdateStatement::value
.
pub fn and_where(&mut self, other: SimpleExpr) -> &mut Self
[src]
And where condition.
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::update() .table(Glyph::Table) .values(vec![ (Glyph::Aspect, 2.1345.into()), (Glyph::Image, "235m".into()), ]) .and_where(Expr::col(Glyph::Id).gt(1)) .and_where(Expr::col(Glyph::Id).lt(3)) .to_owned(); assert_eq!( query.to_string(MysqlQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE (`id` > 1) AND (`id` < 3)"# ); assert_eq!( query.to_string(PostgresQueryBuilder), r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' WHERE ("id" > 1) AND ("id" < 3)"# ); assert_eq!( query.to_string(SqliteQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE (`id` > 1) AND (`id` < 3)"# );
pub fn or_where(&mut self, other: SimpleExpr) -> &mut Self
[src]
Or where condition.
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::update() .table(Glyph::Table) .values(vec![ (Glyph::Aspect, 2.1345.into()), (Glyph::Image, "235m".into()), ]) .or_where(Expr::col(Glyph::Aspect).lt(1)) .or_where(Expr::col(Glyph::Aspect).gt(3)) .to_owned(); assert_eq!( query.to_string(MysqlQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE (`aspect` < 1) OR (`aspect` > 3)"# ); assert_eq!( query.to_string(PostgresQueryBuilder), r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' WHERE ("aspect" < 1) OR ("aspect" > 3)"# ); assert_eq!( query.to_string(SqliteQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE (`aspect` < 1) OR (`aspect` > 3)"# );
pub fn order_by<T: 'static>(&mut self, col: T, order: Order) -> &mut Self where
T: Iden,
[src]
T: Iden,
Order by column.
pub fn order_by_dyn(&mut self, col: Rc<dyn Iden>, order: Order) -> &mut Self
[src]
Order by column, variation of UpdateStatement::order_by
.
pub fn order_by_tbl<T: 'static, C: 'static>(
&mut self,
table: T,
col: C,
order: Order
) -> &mut Self where
T: Iden,
C: Iden,
[src]
&mut self,
table: T,
col: C,
order: Order
) -> &mut Self where
T: Iden,
C: Iden,
Order by column with table name prefix.
pub fn order_by_tbl_dyn(
&mut self,
table: Rc<dyn Iden>,
col: Rc<dyn Iden>,
order: Order
) -> &mut Self
[src]
&mut self,
table: Rc<dyn Iden>,
col: Rc<dyn Iden>,
order: Order
) -> &mut Self
Order by column with table name prefix, variation of UpdateStatement::order_by_tbl
.
pub fn order_by_expr(&mut self, expr: SimpleExpr, order: Order) -> &mut Self
[src]
Order by SimpleExpr
.
pub fn order_by_customs<T: 'static>(
&mut self,
cols: Vec<(T, Order)>
) -> &mut Self where
T: ToString,
[src]
&mut self,
cols: Vec<(T, Order)>
) -> &mut Self where
T: ToString,
Order by custom string.
pub fn order_by_columns<T: 'static>(
&mut self,
cols: Vec<(T, Order)>
) -> &mut Self where
T: Iden,
[src]
&mut self,
cols: Vec<(T, Order)>
) -> &mut Self where
T: Iden,
Order by columns.
pub fn order_by_columns_dyn(
&mut self,
cols: Vec<(Rc<dyn Iden>, Order)>
) -> &mut Self
[src]
&mut self,
cols: Vec<(Rc<dyn Iden>, Order)>
) -> &mut Self
Order by columns, variation of UpdateStatement::order_by_columns
.
pub fn order_by_table_columns<T: 'static, C: 'static>(
&mut self,
cols: Vec<(T, C, Order)>
) -> &mut Self where
T: Iden,
C: Iden,
[src]
&mut self,
cols: Vec<(T, C, Order)>
) -> &mut Self where
T: Iden,
C: Iden,
Order by columns with table prefix.
pub fn order_by_table_columns_dyn(
&mut self,
cols: Vec<(Rc<dyn Iden>, Rc<dyn Iden>, Order)>
) -> &mut Self
[src]
&mut self,
cols: Vec<(Rc<dyn Iden>, Rc<dyn Iden>, Order)>
) -> &mut Self
Order by columns with table prefix, variation of UpdateStatement::order_by_columns
.
pub fn limit(&mut self, limit: u64) -> &mut Self
[src]
Limit number of updated rows.
pub fn build_collect<T: QueryBuilder>(
&self,
query_builder: T,
collector: &mut dyn FnMut(Value)
) -> String
[src]
&self,
query_builder: T,
collector: &mut dyn FnMut(Value)
) -> String
Build corresponding SQL statement for certain database backend and collect query parameters
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::update() .table(Glyph::Table) .values(vec![ (Glyph::Aspect, 2.1345.into()), (Glyph::Image, "235m".into()), ]) .and_where(Expr::col(Glyph::Id).eq(1)) .to_owned(); assert_eq!( query.to_string(MysqlQueryBuilder), r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE `id` = 1"# ); let mut params = Vec::new(); let mut collector = |v| params.push(v); assert_eq!( query.build_collect(MysqlQueryBuilder, &mut collector), r#"UPDATE `glyph` SET `aspect` = ?, `image` = ? WHERE `id` = ?"# ); assert_eq!( params, vec![ Value::Double(2.1345), Value::String(Box::new(String::from("235m"))), Value::Int(1), ] );
pub fn build_collect_any(
&self,
query_builder: &dyn QueryBuilder,
collector: &mut dyn FnMut(Value)
) -> String
[src]
&self,
query_builder: &dyn QueryBuilder,
collector: &mut dyn FnMut(Value)
) -> String
Build corresponding SQL statement for certain database backend and collect query parameters
pub fn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values)
[src]
Build corresponding SQL statement for certain database backend and collect query parameters into a vector
Examples
use sea_query::{*, tests_cfg::*}; let (query, params) = Query::update() .table(Glyph::Table) .values(vec![ (Glyph::Aspect, 2.1345.into()), (Glyph::Image, "235m".into()), ]) .and_where(Expr::col(Glyph::Id).eq(1)) .build(MysqlQueryBuilder); assert_eq!( query, r#"UPDATE `glyph` SET `aspect` = ?, `image` = ? WHERE `id` = ?"# ); assert_eq!( params, Values(vec![ Value::Double(2.1345), Value::String(Box::new(String::from("235m"))), Value::Int(1), ]) );
pub fn build_any(&self, query_builder: &dyn QueryBuilder) -> (String, Values)
[src]
Build corresponding SQL statement for certain database backend and collect query parameters into a vector
pub fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String
[src]
Build corresponding SQL statement for certain database backend and return SQL string
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::update() .table(Glyph::Table) .values(vec![ (Glyph::Aspect, 2.1345.into()), (Glyph::Image, "235m".into()), ]) .and_where(Expr::col(Glyph::Id).eq(1)) .to_string(MysqlQueryBuilder); assert_eq!( query, r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m' WHERE `id` = 1"# );
Trait Implementations
impl Clone for UpdateStatement
[src]
fn clone(&self) -> UpdateStatement
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for UpdateStatement
[src]
impl Default for UpdateStatement
[src]
Auto Trait Implementations
impl !RefUnwindSafe for UpdateStatement
impl !Send for UpdateStatement
impl !Sync for UpdateStatement
impl Unpin for UpdateStatement
impl !UnwindSafe for UpdateStatement
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,