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: 'static>(&mut self, table: T) -> &mut Self where
    T: Iden
[src]

Specify which table to update.

Examples

See UpdateStatement::values

pub fn table_dyn(&mut self, table: Rc<dyn Iden>) -> &mut Self[src]

Specify which table to update, variation of UpdateStatement::table.

Examples

See UpdateStatement::values

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

👎 Deprecated since 0.5.0:

Please use the UpdateStatement::table function instead

pub fn into_table_dyn(&mut self, table: Rc<dyn Iden>) -> &mut Self[src]

👎 Deprecated since 0.5.0:

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]

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]

Update column value by SimpleExpr, variation of UpdateStatement::value_expr.

pub fn json(&mut self, values: JsonValue) -> &mut Self[src]

Update column values by SimpleExpr.

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]

Update column values.

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]

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]

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]

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]

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]

Order by custom string.

pub fn order_by_columns<T: 'static>(
    &mut self,
    cols: Vec<(T, Order)>
) -> &mut Self where
    T: Iden
[src]

Order by columns.

pub fn order_by_columns_dyn(
    &mut self,
    cols: Vec<(Rc<dyn Iden>, Order)>
) -> &mut Self
[src]

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]

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]

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]

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 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> 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.