pub struct OnConflict { /* private fields */ }
Implementations§
Source§impl OnConflict
impl OnConflict
Sourcepub fn new() -> OnConflict
pub fn new() -> OnConflict
Create a ON CONFLICT expression without target column, a special method designed for MySQL
Sourcepub fn column<C>(column: C) -> OnConflictwhere
C: IntoIden,
pub fn column<C>(column: C) -> OnConflictwhere
C: IntoIden,
Set ON CONFLICT target column
Sourcepub fn columns<I, C>(columns: I) -> OnConflictwhere
C: IntoIden,
I: IntoIterator<Item = C>,
pub fn columns<I, C>(columns: I) -> OnConflictwhere
C: IntoIden,
I: IntoIterator<Item = C>,
Set ON CONFLICT target columns
Sourcepub fn expr<T>(&mut self, expr: T) -> &mut OnConflictwhere
T: Into<SimpleExpr>,
pub fn expr<T>(&mut self, expr: T) -> &mut OnConflictwhere
T: Into<SimpleExpr>,
Set ON CONFLICT target expression
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::insert()
.into_table(Glyph::Table)
.columns([Glyph::Aspect, Glyph::Image])
.values_panic(["abcd".into(), 3.1415.into()])
.on_conflict(
OnConflict::new()
.expr(Expr::col(Glyph::Id))
.update_column(Glyph::Aspect)
.value(Glyph::Image, Expr::val(1).add(2))
.to_owned(),
)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
[
r#"INSERT INTO `glyph` (`aspect`, `image`)"#,
r#"VALUES ('abcd', 3.1415)"#,
r#"ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`), `image` = 1 + 2"#,
]
.join(" ")
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
[
r#"INSERT INTO "glyph" ("aspect", "image")"#,
r#"VALUES ('abcd', 3.1415)"#,
r#"ON CONFLICT ("id") DO UPDATE SET "aspect" = "excluded"."aspect", "image" = 1 + 2"#,
]
.join(" ")
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
[
r#"INSERT INTO "glyph" ("aspect", "image")"#,
r#"VALUES ('abcd', 3.1415)"#,
r#"ON CONFLICT ("id") DO UPDATE SET "aspect" = "excluded"."aspect", "image" = 1 + 2"#,
]
.join(" ")
);
Sourcepub fn exprs<I, T>(&mut self, exprs: I) -> &mut OnConflict
pub fn exprs<I, T>(&mut self, exprs: I) -> &mut OnConflict
Set multiple target expressions for ON CONFLICT. See OnConflict::expr
pub fn do_nothing(&mut self) -> &mut OnConflict
Sourcepub fn update_column<C>(&mut self, column: C) -> &mut OnConflictwhere
C: IntoIden,
pub fn update_column<C>(&mut self, column: C) -> &mut OnConflictwhere
C: IntoIden,
Set ON CONFLICT update column
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::insert()
.into_table(Glyph::Table)
.columns([Glyph::Aspect, Glyph::Image])
.values_panic([
"abcd".into(),
3.1415.into(),
])
.on_conflict(
OnConflict::columns([Glyph::Id, Glyph::Aspect])
.update_column(Glyph::Aspect)
.value(Glyph::Image, Expr::val(1).add(2))
.to_owned()
)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
[
r#"INSERT INTO `glyph` (`aspect`, `image`)"#,
r#"VALUES ('abcd', 3.1415)"#,
r#"ON DUPLICATE KEY UPDATE `aspect` = VALUES(`aspect`), `image` = 1 + 2"#,
]
.join(" ")
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
[
r#"INSERT INTO "glyph" ("aspect", "image")"#,
r#"VALUES ('abcd', 3.1415)"#,
r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = "excluded"."aspect", "image" = 1 + 2"#,
]
.join(" ")
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
[
r#"INSERT INTO "glyph" ("aspect", "image")"#,
r#"VALUES ('abcd', 3.1415)"#,
r#"ON CONFLICT ("id", "aspect") DO UPDATE SET "aspect" = "excluded"."aspect", "image" = 1 + 2"#,
]
.join(" ")
);
Sourcepub fn update_columns<C, I>(&mut self, columns: I) -> &mut OnConflictwhere
C: IntoIden,
I: IntoIterator<Item = C>,
pub fn update_columns<C, I>(&mut self, columns: I) -> &mut OnConflictwhere
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""#
);
Sourcepub fn values<C, I>(&mut self, values: I) -> &mut OnConflict
pub fn values<C, I>(&mut self, values: I) -> &mut OnConflict
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 OnConflict
pub fn value<C, T>(&mut self, col: C, value: T) -> &mut OnConflict
Set ON CONFLICT update value
Sourcepub fn target_and_where(&mut self, other: SimpleExpr) -> &mut OnConflict
pub fn target_and_where(&mut self, other: SimpleExpr) -> &mut OnConflict
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 OnConflict
pub fn target_and_where_option( &mut self, other: Option<SimpleExpr>, ) -> &mut OnConflict
Set target WHERE
Sourcepub fn target_cond_where<C>(&mut self, condition: C) -> &mut OnConflictwhere
C: IntoCondition,
pub fn target_cond_where<C>(&mut self, condition: C) -> &mut OnConflictwhere
C: IntoCondition,
Set target WHERE
Sourcepub fn action_and_where(&mut self, other: SimpleExpr) -> &mut OnConflict
pub fn action_and_where(&mut self, other: SimpleExpr) -> &mut OnConflict
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 OnConflict
pub fn action_and_where_option( &mut self, other: Option<SimpleExpr>, ) -> &mut OnConflict
Set action WHERE
Sourcepub fn action_cond_where<C>(&mut self, condition: C) -> &mut OnConflictwhere
C: IntoCondition,
pub fn action_cond_where<C>(&mut self, condition: C) -> &mut OnConflictwhere
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 duplicate 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
Source§impl PartialEq for OnConflict
impl PartialEq for OnConflict
impl StructuralPartialEq for OnConflict
Auto Trait Implementations§
impl Freeze for OnConflict
impl !RefUnwindSafe for OnConflict
impl Send for OnConflict
impl Sync for OnConflict
impl Unpin for OnConflict
impl !UnwindSafe for OnConflict
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more