pub struct ConflictUpdate<D, T> { /* private fields */ }Expand description
The DO UPDATE half of an upsert: everything an UPDATE assigns, plus
excluded, plus the WHERE that decides whether the update fires at
all. An Assignments converts into one, so a request-shaped patch
reaches an upsert as it always did; the reverse doesn’t exist, which is
what keeps a list naming the proposed row out of a statement that has
none.
It carries D for the reason Predicate
does: its WHERE is a condition like any other, and a condition pinned
to one dialect must not reach a statement of another. The statement it
is passed to says which dialect that is, so a value built inline needs
no annotation — one bound to a let and never used does.
Implementations§
Source§impl<D, T: Table> ConflictUpdate<D, T>
impl<D, T: Table> ConflictUpdate<D, T>
Sourcepub fn set_to<C, V, Idxs>(_column: Column<C>, value: V) -> Self
pub fn set_to<C, V, Idxs>(_column: Column<C>, value: V) -> Self
column = <expression>, over the conflicting row and the proposed
one — Assignments::set_to with the wider scope.
Sourcepub fn and_set_to<C, V, Idxs>(self, _column: Column<C>, value: V) -> Self
pub fn and_set_to<C, V, Idxs>(self, _column: Column<C>, value: V) -> Self
One more of them.
Sourcepub fn filter<C: Condition<D, ConflictScope<T>, Idxs>, Idxs>(
self,
cond: C,
) -> Self
pub fn filter<C: Condition<D, ConflictScope<T>, Idxs>, Idxs>( self, cond: C, ) -> Self
DO UPDATE SET .. WHERE <condition> — which conflicting rows the
update actually touches, over the conflicting row and the proposed
one. A row the condition rejects is left as it is and is not
counted, so a one-row upsert’s rows_affected() answers “did this
write anything” rather than always being 1. It counts the rows a
statement wrote, not the branch each took: a multi-row upsert’s
count still folds inserts together with updates, and only zero says
nothing happened.
A different clause from the one partial_index carries: that one
only picks which index the conflict is inferred against.
Sourcepub fn filter_all(
self,
conds: impl IntoIterator<Item = Predicate<D, ConflictScope<T>>>,
) -> Self
pub fn filter_all( self, conds: impl IntoIterator<Item = Predicate<D, ConflictScope<T>>>, ) -> Self
AND-folds a runtime-length collection of discharged conditions, the
same way Update::filter_all
does.
A correlated subquery over the rows this action sees — the same
EXISTS Update::correlated
builds, against the conflicting row and the proposed one.