pub struct UpdateOperation<E: QueryEngine, M: Model> { /* private fields */ }Expand description
Implementations§
Source§impl<E: QueryEngine, M: Model + FromRow> UpdateOperation<E, M>
impl<E: QueryEngine, M: Model + FromRow> UpdateOperation<E, M>
Sourcepub fn set(
self,
column: impl Into<String>,
value: impl Into<FilterValue>,
) -> Self
pub fn set( self, column: impl Into<String>, value: impl Into<FilterValue>, ) -> Self
Set a column to a new value.
Sourcepub fn set_many(
self,
values: impl IntoIterator<Item = (impl Into<String>, impl Into<FilterValue>)>,
) -> Self
pub fn set_many( self, values: impl IntoIterator<Item = (impl Into<String>, impl Into<FilterValue>)>, ) -> Self
Set multiple columns from an iterator.
Sourcepub fn increment(self, column: impl Into<String>, amount: i64) -> Self
pub fn increment(self, column: impl Into<String>, amount: i64) -> Self
Increment a numeric column.
Sourcepub fn set_op(self, column: impl Into<String>, op: WriteOp) -> Self
pub fn set_op(self, column: impl Into<String>, op: WriteOp) -> Self
Apply a column-keyed WriteOp.
Used by with_update_input (and tests) to push an arbitrary
scalar atomic operator onto the update list. The DSL surface
for these operators is the *FieldUpdate wrappers in
crate::inputs::scalar_update.
Sourcepub fn build_sql(&self, dialect: &dyn SqlDialect) -> (String, Vec<FilterValue>)
pub fn build_sql(&self, dialect: &dyn SqlDialect) -> (String, Vec<FilterValue>)
Build the SQL query.
Sourcepub fn with(self, nw: NestedWriteOp) -> Selfwhere
E: SupportsNestedWrites,
pub fn with(self, nw: NestedWriteOp) -> Selfwhere
E: SupportsNestedWrites,
Queue a nested write to run alongside this update.
The parent UPDATE and every queued nested op execute inside a
single implicit transaction — any failure rolls back the parent
UPDATE too.
Nested writes inside update! currently require the where:
filter to equal-match the primary-key column. Non-PK unique
columns (e.g. where: { email: "..." }) error at exec time
with a clear diagnostic. Lifting this restriction needs a
SELECT-then-update pattern to capture the row’s PK — deferred.
Sourcepub async fn exec(self) -> QueryResult<Vec<M>>where
M: Send + 'static,
pub async fn exec(self) -> QueryResult<Vec<M>>where
M: Send + 'static,
Execute the update and return modified records.
Sourcepub async fn exec_one(self) -> QueryResult<M>where
M: Send + 'static,
pub async fn exec_one(self) -> QueryResult<M>where
M: Send + 'static,
Execute the update and return the first modified record.
Sourcepub fn with_where_input<W: WhereUniqueInput<Model = M>>(self, w: W) -> Self
pub fn with_where_input<W: WhereUniqueInput<Model = M>>(self, w: W) -> Self
Apply a typed WhereUniqueInput. AND-composes with any
previously set filter so callers can combine the unique key
with side conditions when they need to.
Sourcepub fn with_select_input<S: SelectInput<Model = M>>(self, s: S) -> Self
pub fn with_select_input<S: SelectInput<Model = M>>(self, s: S) -> Self
Apply a typed SelectInput.
Sourcepub fn with_update_input<I>(self, input: I) -> Selfwhere
I: UpdateInput<Model = M, Data = UpdatePayload>,
pub fn with_update_input<I>(self, input: I) -> Selfwhere
I: UpdateInput<Model = M, Data = UpdatePayload>,
Apply a typed UpdateInput.
The input’s into_ir produces a Vec<(column, WriteOp)> —
each entry is appended to the operation’s SET list. Atomic
operators (Increment/Decrement/Multiply/Divide) emit
col = col <op> $n in the resulting SQL; Set emits
col = $n; Unset emits col = NULL with no placeholder.