pub enum UpsertStrategy {
None,
OnConflictDoNothing(Vec<String>),
OnConflictDoUpdate(Vec<String>, Vec<(String, String)>),
OnDuplicateKeyUpdate(Vec<(String, String)>),
Replace,
}Expand description
Upsert (insert or update) strategy
Supports conflict-handling syntax of three mainstream databases:
- PostgreSQL/SQLite:
ON CONFLICT ... DO NOTHING/DO UPDATE - MySQL/MariaDB/TiDB:
ON DUPLICATE KEY UPDATE/REPLACE INTO
§Dialect compatibility
| Strategy | MySQL | PostgreSQL | SQLite |
|---|---|---|---|
OnConflictDoNothing | ✗ | ✓ | ✓ |
OnConflictDoUpdate | ✗ | ✓ | ✓ |
OnDuplicateKeyUpdate | ✓ | ✗ | ✗ |
Replace | ✓ | ✗ | ✓ (INSERT OR REPLACE) |
Incompatible combinations are skipped in build_with_dialect (no error; the caller
must ensure dialect match).
Variants§
None
No upsert (default)
OnConflictDoNothing(Vec<String>)
PostgreSQL/SQLite: ON CONFLICT (cols) DO NOTHING
OnConflictDoUpdate(Vec<String>, Vec<(String, String)>)
PostgreSQL/SQLite: ON CONFLICT (cols) DO UPDATE SET col = expr, ...
(conflict_cols, update_assignments)
OnDuplicateKeyUpdate(Vec<(String, String)>)
MySQL: ON DUPLICATE KEY UPDATE col = expr, ...
Replace
MySQL: REPLACE INTO (delete conflicting rows first, then insert)
Trait Implementations§
Source§impl Clone for UpsertStrategy
impl Clone for UpsertStrategy
Source§fn clone(&self) -> UpsertStrategy
fn clone(&self) -> UpsertStrategy
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 UpsertStrategy
impl Debug for UpsertStrategy
Source§impl Default for UpsertStrategy
impl Default for UpsertStrategy
Source§fn default() -> UpsertStrategy
fn default() -> UpsertStrategy
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for UpsertStrategy
impl RefUnwindSafe for UpsertStrategy
impl Send for UpsertStrategy
impl Sync for UpsertStrategy
impl Unpin for UpsertStrategy
impl UnsafeUnpin for UpsertStrategy
impl UnwindSafe for UpsertStrategy
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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