pub struct UpdateBuilder<'a, M: Model> { /* private fields */ }Expand description
UPDATE query builder.
§Example
ⓘ
// Update a model instance (uses primary key for WHERE)
update!(hero).execute(cx, &conn).await?;
// Update with explicit SET
UpdateBuilder::<Hero>::empty()
.set("age", 26)
.set("name", "New Name")
.filter(Expr::col("id").eq(42))
.execute(cx, &conn).await?;
// Update with RETURNING
let row = update!(hero).returning().execute_returning(cx, &conn).await?;Implementations§
Source§impl<'a, M: Model> UpdateBuilder<'a, M>
impl<'a, M: Model> UpdateBuilder<'a, M>
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create an empty UPDATE builder for explicit SET operations.
Use this when you want to update specific columns without a model instance.
Sourcepub fn set<V: Into<Value>>(self, column: &str, value: V) -> Self
pub fn set<V: Into<Value>>(self, column: &str, value: V) -> Self
Set a column to a specific value.
This can be used with or without a model instance. When used with a model, these explicit sets override the model values.
Sourcepub fn set_only(self, fields: &[&'static str]) -> Self
pub fn set_only(self, fields: &[&'static str]) -> Self
Only update specific fields from the model.
Sourcepub fn build(&self) -> (String, Vec<Value>)
pub fn build(&self) -> (String, Vec<Value>)
Build the UPDATE SQL and parameters with default dialect (Postgres).
Sourcepub fn build_with_dialect(&self, dialect: Dialect) -> (String, Vec<Value>)
pub fn build_with_dialect(&self, dialect: Dialect) -> (String, Vec<Value>)
Build the UPDATE SQL and parameters with specific dialect.
Sourcepub async fn execute<C: Connection>(
self,
cx: &Cx,
conn: &C,
) -> Outcome<u64, Error>
pub async fn execute<C: Connection>( self, cx: &Cx, conn: &C, ) -> Outcome<u64, Error>
Execute the UPDATE and return rows affected.
Sourcepub async fn execute_returning<C: Connection>(
self,
cx: &Cx,
conn: &C,
) -> Outcome<Vec<Row>, Error>
pub async fn execute_returning<C: Connection>( self, cx: &Cx, conn: &C, ) -> Outcome<Vec<Row>, Error>
Execute the UPDATE with RETURNING and get the updated rows.
Trait Implementations§
Auto Trait Implementations§
impl<'a, M> Freeze for UpdateBuilder<'a, M>
impl<'a, M> RefUnwindSafe for UpdateBuilder<'a, M>where
M: RefUnwindSafe,
impl<'a, M> Send for UpdateBuilder<'a, M>
impl<'a, M> Sync for UpdateBuilder<'a, M>
impl<'a, M> Unpin for UpdateBuilder<'a, M>
impl<'a, M> UnwindSafe for UpdateBuilder<'a, M>where
M: RefUnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).