pub struct UpsertOperation<E: QueryEngine, M: Model> { /* private fields */ }Expand description
An upsert (insert or update) operation.
§Example
ⓘ
let user = client
.user()
.upsert()
.r#where(user::email::equals("test@example.com"))
.create(user::Create { email: "test@example.com".into(), name: Some("Test".into()) })
.update(user::Update { name: Some("Updated".into()), ..Default::default() })
.exec()
.await?;Implementations§
Source§impl<E: QueryEngine, M: Model> UpsertOperation<E, M>
impl<E: QueryEngine, M: Model> UpsertOperation<E, M>
Sourcepub fn where(self, filter: impl Into<Filter>) -> Self
pub fn where(self, filter: impl Into<Filter>) -> Self
Add a filter condition (identifies the record to upsert).
Sourcepub fn on_conflict(
self,
columns: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn on_conflict( self, columns: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Set the columns to check for conflict.
Sourcepub fn create(
self,
values: impl IntoIterator<Item = (impl Into<String>, impl Into<FilterValue>)>,
) -> Self
pub fn create( self, values: impl IntoIterator<Item = (impl Into<String>, impl Into<FilterValue>)>, ) -> Self
Set the create data.
Sourcepub fn create_set(
self,
column: impl Into<String>,
value: impl Into<FilterValue>,
) -> Self
pub fn create_set( self, column: impl Into<String>, value: impl Into<FilterValue>, ) -> Self
Set a single create column.
Sourcepub fn update(
self,
values: impl IntoIterator<Item = (impl Into<String>, impl Into<FilterValue>)>,
) -> Self
pub fn update( self, values: impl IntoIterator<Item = (impl Into<String>, impl Into<FilterValue>)>, ) -> Self
Set the update data.
Sourcepub fn update_set(
self,
column: impl Into<String>,
value: impl Into<FilterValue>,
) -> Self
pub fn update_set( self, column: impl Into<String>, value: impl Into<FilterValue>, ) -> Self
Set a single update column.
Sourcepub fn build_sql(&self) -> (String, Vec<FilterValue>)
pub fn build_sql(&self) -> (String, Vec<FilterValue>)
Build the SQL query.
Sourcepub async fn exec(self) -> QueryResult<M>where
M: Send + 'static,
pub async fn exec(self) -> QueryResult<M>where
M: Send + 'static,
Execute the upsert and return the record.
Auto Trait Implementations§
impl<E, M> Freeze for UpsertOperation<E, M>where
E: Freeze,
impl<E, M> RefUnwindSafe for UpsertOperation<E, M>where
E: RefUnwindSafe,
M: RefUnwindSafe,
impl<E, M> Send for UpsertOperation<E, M>
impl<E, M> Sync for UpsertOperation<E, M>
impl<E, M> Unpin for UpsertOperation<E, M>
impl<E, M> UnwindSafe for UpsertOperation<E, M>where
E: UnwindSafe,
M: UnwindSafe,
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