Struct sea_query::query::OnConflict
source · [−]pub struct OnConflict { /* private fields */ }
Implementations
sourceimpl 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(vec![
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""#
);
sourcepub fn update_value<C>(&mut self, column_value: (C, Value)) -> &mut Selfwhere
C: IntoIden,
pub fn update_value<C>(&mut self, column_value: (C, Value)) -> &mut Selfwhere
C: IntoIden,
Set ON CONFLICT update value
sourcepub fn update_values<C, I>(&mut self, column_values: I) -> &mut Selfwhere
C: IntoIden,
I: IntoIterator<Item = (C, Value)>,
pub fn update_values<C, I>(&mut self, column_values: I) -> &mut Selfwhere
C: IntoIden,
I: IntoIterator<Item = (C, Value)>,
Set ON CONFLICT update values
Examples
use sea_query::{tests_cfg::*, *};
let query = Query::insert()
.into_table(Glyph::Table)
.columns([Glyph::Aspect, Glyph::Image])
.values_panic(vec![
2.into(),
3.into(),
])
.on_conflict(
OnConflict::column(Glyph::Id)
.update_values([
(Glyph::Aspect, "04108048005887010020060000204E0180400400".into()),
(Glyph::Image, 3.1415.into()),
])
.to_owned()
)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"INSERT INTO `glyph` (`aspect`, `image`) VALUES (2, 3) ON DUPLICATE KEY UPDATE `aspect` = '04108048005887010020060000204E0180400400', `image` = 3.1415"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2, 3) ON CONFLICT ("id") DO UPDATE SET "aspect" = '04108048005887010020060000204E0180400400', "image" = 3.1415"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"INSERT INTO "glyph" ("aspect", "image") VALUES (2, 3) ON CONFLICT ("id") DO UPDATE SET "aspect" = '04108048005887010020060000204E0180400400', "image" = 3.1415"#
);
sourcepub fn update_expr<C>(&mut self, column_expr: (C, SimpleExpr)) -> &mut Selfwhere
C: IntoIden,
pub fn update_expr<C>(&mut self, column_expr: (C, SimpleExpr)) -> &mut Selfwhere
C: IntoIden,
Set ON CONFLICT update expr
sourcepub fn update_exprs<C, I>(&mut self, column_exprs: I) -> &mut Selfwhere
C: IntoIden,
I: IntoIterator<Item = (C, SimpleExpr)>,
pub fn update_exprs<C, I>(&mut self, column_exprs: 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(vec![
2.into(),
3.into(),
])
.on_conflict(
OnConflict::column(Glyph::Id)
.update_expr((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"#
);
Trait Implementations
sourceimpl Clone for OnConflict
impl Clone for OnConflict
sourcefn clone(&self) -> OnConflict
fn clone(&self) -> OnConflict
Returns a copy of the value. Read more
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for OnConflict
impl Debug for OnConflict
sourceimpl Default for OnConflict
impl Default for OnConflict
sourcefn default() -> OnConflict
fn default() -> OnConflict
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl !RefUnwindSafe for OnConflict
impl Send for OnConflict
impl Sync for OnConflict
impl Unpin for OnConflict
impl !UnwindSafe for OnConflict
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more