pub struct UpsertStatement<'a> {
pub table_name: &'a str,
pub values: Vec<(&'a str, Box<dyn Expression>)>,
pub filters: Option<Vec<Box<dyn BooleanExpression>>>,
pub unique: Option<&'a [&'a str]>,
pub limit: Option<usize>,
}Expand description
UPSERT statement for inserting or updating a row on conflict
Fields§
§table_name: &'a strTable to upsert into
values: Vec<(&'a str, Box<dyn Expression>)>Column-value pairs to insert/update
filters: Option<Vec<Box<dyn BooleanExpression>>>WHERE clause filters for conditional upsert
unique: Option<&'a [&'a str]>Columns that form the unique constraint to detect conflicts
limit: Option<usize>Maximum number of rows to upsert
Implementations§
Source§impl<'a> UpsertStatement<'a>
impl<'a> UpsertStatement<'a>
Sourcepub fn values<T>(self, values: Vec<(&'a str, T)>) -> UpsertStatement<'a>
pub fn values<T>(self, values: Vec<(&'a str, T)>) -> UpsertStatement<'a>
Sets multiple column-value pairs to upsert
Sourcepub fn value<T>(self, name: &'a str, value: T) -> UpsertStatement<'a>
pub fn value<T>(self, name: &'a str, value: T) -> UpsertStatement<'a>
Sets a single column-value pair to upsert
Sourcepub fn value_opt<T>(
self,
name: &'a str,
value: Option<T>,
) -> UpsertStatement<'a>
pub fn value_opt<T>( self, name: &'a str, value: Option<T>, ) -> UpsertStatement<'a>
Sets a column-value pair only if the value is Some
This is useful for conditional updates where a value should only be set if present.
Sourcepub const fn unique(self, unique: &'a [&'a str]) -> UpsertStatement<'a>
pub const fn unique(self, unique: &'a [&'a str]) -> UpsertStatement<'a>
Specifies unique columns that identify conflicts
These columns determine when to update instead of insert.
Sourcepub const fn limit(self, limit: usize) -> UpsertStatement<'a>
pub const fn limit(self, limit: usize) -> UpsertStatement<'a>
Limits the number of rows affected by the upsert
Sourcepub async fn execute(self, db: &dyn Database) -> Result<Vec<Row>, DatabaseError>
pub async fn execute(self, db: &dyn Database) -> Result<Vec<Row>, DatabaseError>
§Errors
Will return Err if the upsert execution failed.
Sourcepub async fn execute_first(
self,
db: &dyn Database,
) -> Result<Row, DatabaseError>
pub async fn execute_first( self, db: &dyn Database, ) -> Result<Row, DatabaseError>
§Errors
Will return Err if the upsert execution failed.
Trait Implementations§
Source§impl Executable for UpsertStatement<'_>
Implement Executable for UpsertStatement
impl Executable for UpsertStatement<'_>
Implement Executable for UpsertStatement
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 dyn Database,
) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
UpsertStatement<'_>: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 dyn Database,
) -> Pin<Box<dyn Future<Output = Result<(), DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
UpsertStatement<'_>: 'async_trait,
Source§impl FilterableQuery for UpsertStatement<'_>
impl FilterableQuery for UpsertStatement<'_>
Source§fn filter(self, filter: Box<dyn BooleanExpression>) -> UpsertStatement<'_>
fn filter(self, filter: Box<dyn BooleanExpression>) -> UpsertStatement<'_>
Source§fn filters(self, filters: Vec<Box<dyn BooleanExpression>>) -> Self
fn filters(self, filters: Vec<Box<dyn BooleanExpression>>) -> Self
Source§fn filter_if_some<T>(self, filter: Option<T>) -> Selfwhere
T: BooleanExpression + 'static,
fn filter_if_some<T>(self, filter: Option<T>) -> Selfwhere
T: BooleanExpression + 'static,
Source§fn where_in<L, V>(self, left: L, values: V) -> Self
fn where_in<L, V>(self, left: L, values: V) -> Self
Source§fn where_not_in<L, V>(self, left: L, values: V) -> Self
fn where_not_in<L, V>(self, left: L, values: V) -> Self
Source§fn where_and(self, conditions: Vec<Box<dyn BooleanExpression>>) -> Self
fn where_and(self, conditions: Vec<Box<dyn BooleanExpression>>) -> Self
Source§fn where_or(self, conditions: Vec<Box<dyn BooleanExpression>>) -> Self
fn where_or(self, conditions: Vec<Box<dyn BooleanExpression>>) -> Self
Source§fn where_eq<L, R>(self, left: L, right: R) -> Self
fn where_eq<L, R>(self, left: L, right: R) -> Self
Source§fn where_not_eq<L, R>(self, left: L, right: R) -> Self
fn where_not_eq<L, R>(self, left: L, right: R) -> Self
Source§fn where_gt<L, R>(self, left: L, right: R) -> Self
fn where_gt<L, R>(self, left: L, right: R) -> Self
Source§fn where_gte<L, R>(self, left: L, right: R) -> Self
fn where_gte<L, R>(self, left: L, right: R) -> Self
Source§fn where_lt<L, R>(self, left: L, right: R) -> Self
fn where_lt<L, R>(self, left: L, right: R) -> Self
Source§impl<'a> From<UpsertStatement<'a>> for SelectQuery<'a>
impl<'a> From<UpsertStatement<'a>> for SelectQuery<'a>
Source§fn from(value: UpsertStatement<'a>) -> SelectQuery<'a>
fn from(value: UpsertStatement<'a>) -> SelectQuery<'a>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for UpsertStatement<'a>
impl<'a> !UnwindSafe for UpsertStatement<'a>
impl<'a> Freeze for UpsertStatement<'a>
impl<'a> Send for UpsertStatement<'a>
impl<'a> Sync for UpsertStatement<'a>
impl<'a> Unpin for UpsertStatement<'a>
impl<'a> UnsafeUnpin for UpsertStatement<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
impl<T> HandlerSend for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request