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]

pub fn new() -> Self[src]

Construct a new UpdateStatement

pub fn table<T>(&mut self, tbl_ref: T) -> &mut Self where
    T: IntoTableRef
[src]

Specify which table to update.

Examples

See UpdateStatement::values

pub fn into_table<T>(&mut self, table: T) -> &mut Self where
    T: IntoTableRef
[src]

👎 Deprecated since 0.5.0:

Please use the UpdateStatement::table function instead

pub fn value_expr<T>(&mut self, col: T, exp: SimpleExpr) -> &mut Self where
    T: IntoIden
[src]

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]

This is supported on crate feature 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]

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]

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]

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]

👎 Deprecated since 0.9.0:

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]

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]

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]

👎 Deprecated since 0.9.0:

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]

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]

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 Debug for UpdateStatement[src]

impl Default for UpdateStatement[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,