Struct sea_query::query::UpdateStatement [−][src]
pub struct UpdateStatement { /* fields omitted */ }
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]
impl UpdateStatement
[src]pub fn new() -> Self
[src]
Construct a new UpdateStatement
pub fn table<T>(&mut self, tbl_ref: T) -> &mut Self where
T: IntoTableRef,
[src]
T: IntoTableRef,
pub fn into_table<T>(&mut self, table: T) -> &mut Self where
T: IntoTableRef,
[src]
T: IntoTableRef,
Please use the UpdateStatement::table function instead
pub fn value_expr<T>(&mut self, col: T, exp: SimpleExpr) -> &mut Self where
T: IntoIden,
[src]
T: IntoIden,
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 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, I>(&mut self, values: I) -> &mut Self where
T: IntoIden,
I: IntoIterator<Item = (T, Value)>,
[src]
T: IntoIden,
I: IntoIterator<Item = (T, Value)>,
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 value<T>(&mut self, col: T, value: Value) -> &mut Self where
T: IntoIden,
[src]
T: IntoIden,
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 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>(&mut self, col: T, order: Order) -> &mut Self where
T: IntoColumnRef,
[src]
T: IntoColumnRef,
Order by column.
pub fn order_by_tbl<T, C>(
&mut self,
table: T,
col: C,
order: Order
) -> &mut Self where
T: IntoIden,
C: IntoIden,
[src]
&mut self,
table: T,
col: C,
order: Order
) -> &mut Self where
T: IntoIden,
C: IntoIden,
Please use the [UpdateStatement::order_by
] with a tuple as [ColumnRef
]
pub fn order_by_expr(&mut self, expr: SimpleExpr, order: Order) -> &mut Self
[src]
Order by SimpleExpr
.
pub fn order_by_customs<T, I>(&mut self, cols: I) -> &mut Self where
T: ToString,
I: IntoIterator<Item = (T, Order)>,
[src]
T: ToString,
I: IntoIterator<Item = (T, Order)>,
Order by custom string.
pub fn order_by_columns<T, I>(&mut self, cols: I) -> &mut Self where
T: IntoColumnRef,
I: IntoIterator<Item = (T, Order)>,
[src]
T: IntoColumnRef,
I: IntoIterator<Item = (T, Order)>,
Order by vector of columns.
pub fn order_by_table_columns<T, C, I>(&mut self, cols: I) -> &mut Self where
T: IntoIden,
C: IntoIden,
I: IntoIterator<Item = (T, C, Order)>,
[src]
T: IntoIden,
C: IntoIden,
I: IntoIterator<Item = (T, C, Order)>,
Please use the [UpdateStatement::order_by_columns
] with a tuple as [ColumnRef
]
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]
impl Clone for UpdateStatement
[src]fn clone(&self) -> UpdateStatement
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for UpdateStatement
[src]
impl Default for UpdateStatement
[src]Auto Trait Implementations
impl !RefUnwindSafe for UpdateStatement
impl !RefUnwindSafe for UpdateStatement
impl !Send for UpdateStatement
impl !Send for UpdateStatement
impl !Sync for UpdateStatement
impl !Sync for UpdateStatement
impl Unpin for UpdateStatement
impl Unpin for UpdateStatement
impl !UnwindSafe for UpdateStatement
impl !UnwindSafe for UpdateStatement