Skip to main content

UpdateBuilder

Struct UpdateBuilder 

Source
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>

Source

pub fn new(model: &'a M) -> Self

Create a new UPDATE builder for the given model instance.

Source

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.

Source

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.

Source

pub fn set_only(self, fields: &[&'static str]) -> Self

Only update specific fields from the model.

Source

pub fn filter(self, expr: Expr) -> Self

Add a WHERE condition (defaults to primary key match).

Source

pub fn returning(self) -> Self

Add RETURNING * clause to return the updated row(s).

Source

pub fn build(&self) -> (String, Vec<Value>)

Build the UPDATE SQL and parameters with default dialect (Postgres).

Source

pub fn build_with_dialect(&self, dialect: Dialect) -> (String, Vec<Value>)

Build the UPDATE SQL and parameters with specific dialect.

Source

pub async fn execute<C: Connection>( self, cx: &Cx, conn: &C, ) -> Outcome<u64, Error>

Execute the UPDATE and return rows affected.

Source

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§

Source§

impl<'a, M: Debug + Model> Debug for UpdateBuilder<'a, M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more