pub struct InsertBuilder<'a, M: Model> { /* private fields */ }Expand description
Implementations§
Source§impl<'a, M: Model> InsertBuilder<'a, M>
impl<'a, M: Model> InsertBuilder<'a, M>
Sourcepub fn returning(self) -> Self
pub fn returning(self) -> Self
Add RETURNING * clause to return the inserted row.
Use with execute_returning() to get the inserted row.
Sourcepub fn on_conflict_do_nothing(self) -> Self
pub fn on_conflict_do_nothing(self) -> Self
Handle conflicts by doing nothing (PostgreSQL ON CONFLICT DO NOTHING).
This allows the insert to silently succeed even if it would violate a unique constraint.
Sourcepub fn on_conflict_do_update(self, columns: &[&str]) -> Self
pub fn on_conflict_do_update(self, columns: &[&str]) -> Self
Sourcepub fn on_conflict_target_do_update(
self,
target: &[&str],
columns: &[&str],
) -> Self
pub fn on_conflict_target_do_update( self, target: &[&str], columns: &[&str], ) -> Self
Handle conflicts by updating columns with a specific conflict target.
§Arguments
target- The columns that form the unique constraint to matchcolumns- The columns to update on conflict
Sourcepub fn build(&self) -> (String, Vec<Value>)
pub fn build(&self) -> (String, Vec<Value>)
Build the INSERT 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 INSERT SQL and parameters with specific dialect.
Sourcepub async fn execute<C: Connection>(
self,
cx: &Cx,
conn: &C,
) -> Outcome<i64, Error>
pub async fn execute<C: Connection>( self, cx: &Cx, conn: &C, ) -> Outcome<i64, Error>
Execute the INSERT and return the inserted ID.
Sourcepub async fn execute_returning<C: Connection>(
self,
cx: &Cx,
conn: &C,
) -> Outcome<Option<Row>, Error>
pub async fn execute_returning<C: Connection>( self, cx: &Cx, conn: &C, ) -> Outcome<Option<Row>, Error>
Execute the INSERT with RETURNING and get the inserted row.
This automatically adds RETURNING * and returns the full row.
Trait Implementations§
Auto Trait Implementations§
impl<'a, M> Freeze for InsertBuilder<'a, M>
impl<'a, M> RefUnwindSafe for InsertBuilder<'a, M>where
M: RefUnwindSafe,
impl<'a, M> Send for InsertBuilder<'a, M>
impl<'a, M> Sync for InsertBuilder<'a, M>
impl<'a, M> Unpin for InsertBuilder<'a, M>
impl<'a, M> UnwindSafe for InsertBuilder<'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).