pub struct OnConflict { /* private fields */ }

Implementations§

§

impl OnConflict

pub fn new() -> OnConflict

Create a ON CONFLICT expression without target column, a special method designed for MySQL

pub fn column<C>(column: C) -> OnConflictwhere C: IntoIden,

Set ON CONFLICT target column

pub fn columns<I, C>(columns: I) -> OnConflictwhere C: IntoIden, I: IntoIterator<Item = C>,

Set ON CONFLICT target columns

pub fn do_nothing(&mut self) -> &mut OnConflict

pub fn update_column<C>(&mut self, column: C) -> &mut OnConflictwhere C: IntoIden,

Set ON CONFLICT update column

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""#
);

pub fn update_value<C>(&mut self, column_value: (C, Value)) -> &mut OnConflictwhere C: IntoIden,

👎Deprecated since 0.27.0: Please use the [OnConflict::value]

pub fn update_values<C, I>(&mut self, column_values: I) -> &mut OnConflictwhere 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 OnConflictwhere 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 OnConflictwhere C: IntoIden, I: IntoIterator<Item = (C, SimpleExpr)>,

👎Deprecated since 0.27.0: Please use the [OnConflict::values]

pub fn values<C, I>(&mut self, values: I) -> &mut OnConflictwhere 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"#
);

pub fn value<C, T>(&mut self, col: C, value: T) -> &mut OnConflictwhere C: IntoIden, T: Into<SimpleExpr>,

Set ON CONFLICT update value

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"#
);

pub fn target_and_where_option( &mut self, other: Option<SimpleExpr> ) -> &mut OnConflict

Set target WHERE

pub fn target_cond_where<C>(&mut self, condition: C) -> &mut OnConflictwhere C: IntoCondition,

Set target WHERE

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"#
);

pub fn action_and_where_option( &mut self, other: Option<SimpleExpr> ) -> &mut OnConflict

Set action WHERE

pub fn action_cond_where<C>(&mut self, condition: C) -> &mut OnConflictwhere C: IntoCondition,

Set action WHERE

Trait Implementations§

§

impl Clone for OnConflict

§

fn clone(&self) -> OnConflict

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for OnConflict

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for OnConflict

§

fn default() -> OnConflict

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more