Struct sea_query::query::OnConflict
source ยท pub struct OnConflict { /* private fields */ }
Implementationsยง
sourceยงimpl OnConflict
impl OnConflict
sourcepub fn new() -> Self
pub fn new() -> Self
Create a ON CONFLICT expression without target column, a special method designed for MySQL
sourcepub fn columns<I, C>(columns: I) -> Selfwhere
C: IntoIden,
I: IntoIterator<Item = C>,
pub fn columns<I, C>(columns: I) -> Selfwhere
C: IntoIden,
I: IntoIterator<Item = C>,
Set ON CONFLICT target columns
pub fn do_nothing(&mut self) -> &mut Self
sourcepub fn update_column<C>(&mut self, column: C) -> &mut Selfwhere
C: IntoIden,
pub fn update_column<C>(&mut self, column: C) -> &mut Selfwhere
C: IntoIden,
Set ON CONFLICT update column
sourcepub fn update_columns<C, I>(&mut self, columns: I) -> &mut Selfwhere
C: IntoIden,
I: IntoIterator<Item = C>,
pub fn update_columns<C, I>(&mut self, columns: I) -> &mut Selfwhere
C: IntoIden,
I: IntoIterator<Item = C>,
Set ON CONFLICT update columns
Examples
use sea_query::{tests_cfg::*, *};
let query = Query::insert()
.into_table(Glyph::Table)
.columns([Glyph::Aspect, Glyph::Image])
.values_panic([
2.into(),
3.into(),
])
.on_conflict(
OnConflict::column(Glyph::Id)
.update_columns([Glyph::Aspect, Glyph::Image])
.to_owned(),
)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"INSERT INTO `glyph` (`aspect`, `image`) VALUES (2, 3) ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`), `image` = VALUES(`image`)"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2, 3) ON CONFLICT ("id") DO UPDATE SET "aspect" = "excluded"."aspect", "image" = "excluded"."image""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2, 3) ON CONFLICT ("id") DO UPDATE SET "aspect" = "excluded"."aspect", "image" = "excluded"."image""#
);
pub fn update_value<C>(&mut self, column_value: (C, Value)) -> &mut Selfwhere
C: IntoIden,
๐Deprecated since 0.27.0: Please use the [
OnConflict::value
]pub fn update_values<C, I>(&mut self, column_values: I) -> &mut Selfwhere
C: IntoIden,
I: IntoIterator<Item = (C, Value)>,
๐Deprecated since 0.27.0: Please use the [
OnConflict::values
]pub fn update_expr<C, E>(&mut self, col_expr: (C, E)) -> &mut Selfwhere
C: IntoIden,
E: Into<SimpleExpr>,
๐Deprecated since 0.27.0: Please use the [
OnConflict::value
]pub fn update_exprs<C, I>(&mut self, values: I) -> &mut Selfwhere
C: IntoIden,
I: IntoIterator<Item = (C, SimpleExpr)>,
๐Deprecated since 0.27.0: Please use the [
OnConflict::values
]sourcepub fn values<C, I>(&mut self, values: I) -> &mut Selfwhere
C: IntoIden,
I: IntoIterator<Item = (C, SimpleExpr)>,
pub fn values<C, I>(&mut self, values: I) -> &mut Selfwhere
C: IntoIden,
I: IntoIterator<Item = (C, SimpleExpr)>,
Set ON CONFLICT update exprs
Examples
use sea_query::{tests_cfg::*, *};
let query = Query::insert()
.into_table(Glyph::Table)
.columns([Glyph::Aspect, Glyph::Image])
.values_panic([
2.into(),
3.into(),
])
.on_conflict(
OnConflict::column(Glyph::Id)
.value(Glyph::Image, Expr::val(1).add(2))
.to_owned()
)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"INSERT INTO `glyph` (`aspect`, `image`) VALUES (2, 3) ON DUPLICATE KEY UPDATE `image` = 1 + 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2, 3) ON CONFLICT ("id") DO UPDATE SET "image" = 1 + 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2, 3) ON CONFLICT ("id") DO UPDATE SET "image" = 1 + 2"#
);
sourcepub fn value<C, T>(&mut self, col: C, value: T) -> &mut Selfwhere
C: IntoIden,
T: Into<SimpleExpr>,
pub fn value<C, T>(&mut self, col: C, value: T) -> &mut Selfwhere
C: IntoIden,
T: Into<SimpleExpr>,
Set ON CONFLICT update value
sourcepub fn target_and_where(&mut self, other: SimpleExpr) -> &mut Self
pub fn target_and_where(&mut self, other: SimpleExpr) -> &mut Self
Set target WHERE
Examples
use sea_query::{tests_cfg::*, *};
let query = Query::insert()
.into_table(Glyph::Table)
.columns([Glyph::Aspect, Glyph::Image])
.values_panic([
2.into(),
3.into(),
])
.on_conflict(
OnConflict::column(Glyph::Id)
.value(Glyph::Image, Expr::val(1).add(2))
.target_and_where(Expr::col((Glyph::Table, Glyph::Aspect)).is_null())
.to_owned()
)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"INSERT INTO `glyph` (`aspect`, `image`) VALUES (2, 3) ON DUPLICATE KEY UPDATE `image` = 1 + 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2, 3) ON CONFLICT ("id") WHERE "glyph"."aspect" IS NULL DO UPDATE SET "image" = 1 + 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2, 3) ON CONFLICT ("id") WHERE "glyph"."aspect" IS NULL DO UPDATE SET "image" = 1 + 2"#
);
sourcepub fn target_and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self
pub fn target_and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self
Set target WHERE
sourcepub fn target_cond_where<C>(&mut self, condition: C) -> &mut Selfwhere
C: IntoCondition,
pub fn target_cond_where<C>(&mut self, condition: C) -> &mut Selfwhere
C: IntoCondition,
Set target WHERE
sourcepub fn action_and_where(&mut self, other: SimpleExpr) -> &mut Self
pub fn action_and_where(&mut self, other: SimpleExpr) -> &mut Self
Set action WHERE
Examples
use sea_query::{tests_cfg::*, *};
let query = Query::insert()
.into_table(Glyph::Table)
.columns([Glyph::Aspect, Glyph::Image])
.values_panic([
2.into(),
3.into(),
])
.on_conflict(
OnConflict::column(Glyph::Id)
.value(Glyph::Image, Expr::val(1).add(2))
.action_and_where(Expr::col((Glyph::Table, Glyph::Aspect)).is_null())
.to_owned()
)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"INSERT INTO `glyph` (`aspect`, `image`) VALUES (2, 3) ON DUPLICATE KEY UPDATE `image` = 1 + 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2, 3) ON CONFLICT ("id") DO UPDATE SET "image" = 1 + 2 WHERE "glyph"."aspect" IS NULL"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2, 3) ON CONFLICT ("id") DO UPDATE SET "image" = 1 + 2 WHERE "glyph"."aspect" IS NULL"#
);
sourcepub fn action_and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self
pub fn action_and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self
Set action WHERE
sourcepub fn action_cond_where<C>(&mut self, condition: C) -> &mut Selfwhere
C: IntoCondition,
pub fn action_cond_where<C>(&mut self, condition: C) -> &mut Selfwhere
C: IntoCondition,
Set action WHERE
Trait Implementationsยง
sourceยงimpl Clone for OnConflict
impl Clone for OnConflict
sourceยงfn clone(&self) -> OnConflict
fn clone(&self) -> OnConflict
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 Debug for OnConflict
impl Debug for OnConflict
sourceยงimpl Default for OnConflict
impl Default for OnConflict
sourceยงfn default() -> OnConflict
fn default() -> OnConflict
Returns the โdefault valueโ for a type. Read more