pub enum UpsertOutcome<M> {
Inserted(M),
Existing(M),
}Expand description
Outcome of a .upsert(..).do_nothing().run(..) call.
§Race semantics
The runtime always resolves the conflict under a SELECT ... FOR UPDATE row lock held for the lifetime of the surrounding
transaction (see upsert_do_nothing_exec::run_upsert_do_nothing_in_tx
for the exact sequencing):
- If the probe finds an existing row, that row is locked before this
call returns — no concurrent transaction can delete or modify it
until the caller commits — so
Existingis a guarantee about the row’s state at the moment this call returns, not merely “at some point during the call”. - If the probe finds nothing, the actual
INSERT ... ON CONFLICT DO NOTHINGis still the statement that runs (not a plainINSERT), because the probe’s “no row” answer does not itself lock anything — a concurrent transaction can commit a conflicting row in the gap between the probe and the INSERT. When that race is lost, the runtime performs one more locked read to hand back the row the other transaction actually committed, so callers never see a phantom “existing” row invented from stale data — seeExistingbelow for what happens if that row is deleted before the fallback read completes.
Variants§
Inserted(M)
This call performed the insert. No row previously existed at the conflict target.
Existing(M)
A row already existed at the conflict target and was left
completely untouched by this call — no columns written, no
Updated event emitted, no audit entry recorded, because
nothing about the row changed.
If this outcome was reached via the race-fallback path (the
insert branch lost a concurrent-insert race and had to read the
winning row back), and that row was deleted before the
fallback read could complete, the call surfaces
CoolError::Conflict instead of ever constructing an
Existing from data that might not be current — see
upsert_do_nothing_exec for that narrower race.
Implementations§
Source§impl<M> UpsertOutcome<M>
impl<M> UpsertOutcome<M>
Sourcepub fn was_inserted(&self) -> bool
pub fn was_inserted(&self) -> bool
true for Self::Inserted.
Sourcepub fn into_record(self) -> M
pub fn into_record(self) -> M
Discard the inserted-vs-existing distinction and take the row.
Prefer matching on the enum when the distinction matters (that’s
the entire reason this type exists) — this is for callers that
only ever need the record, e.g. read-modify-report call sites
that already branched on Self::was_inserted.
Trait Implementations§
Source§impl<M: Clone> Clone for UpsertOutcome<M>
impl<M: Clone> Clone for UpsertOutcome<M>
Source§fn clone(&self) -> UpsertOutcome<M>
fn clone(&self) -> UpsertOutcome<M>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<M: Debug> Debug for UpsertOutcome<M>
impl<M: Debug> Debug for UpsertOutcome<M>
impl<M: Eq> Eq for UpsertOutcome<M>
Source§impl<M: PartialEq> PartialEq for UpsertOutcome<M>
impl<M: PartialEq> PartialEq for UpsertOutcome<M>
impl<M: PartialEq> StructuralPartialEq for UpsertOutcome<M>
Auto Trait Implementations§
impl<M> Freeze for UpsertOutcome<M>where
M: Freeze,
impl<M> RefUnwindSafe for UpsertOutcome<M>where
M: RefUnwindSafe,
impl<M> Send for UpsertOutcome<M>where
M: Send,
impl<M> Sync for UpsertOutcome<M>where
M: Sync,
impl<M> Unpin for UpsertOutcome<M>where
M: Unpin,
impl<M> UnsafeUnpin for UpsertOutcome<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for UpsertOutcome<M>where
M: UnwindSafe,
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
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> ⓘ
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> ⓘ
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