pub struct Upsert {
pub table: String,
pub columns: Vec<String>,
pub values: Vec<String>,
pub conflict_target: Option<ConflictTarget>,
pub conflict_action: ConflictAction,
pub where_clause: Option<String>,
pub returning: Option<Vec<String>>,
}Expand description
An upsert operation (INSERT with conflict handling).
Fields§
§table: StringTable name.
columns: Vec<String>Columns to insert.
values: Vec<String>Values to insert (expressions or placeholders).
conflict_target: Option<ConflictTarget>Conflict target specification.
conflict_action: ConflictActionAction to take on conflict.
where_clause: Option<String>WHERE clause for conflict update (PostgreSQL).
returning: Option<Vec<String>>RETURNING clause (PostgreSQL).
Implementations§
Source§impl Upsert
impl Upsert
Sourcepub fn builder(table: impl Into<String>) -> UpsertBuilder
pub fn builder(table: impl Into<String>) -> UpsertBuilder
Create an upsert builder.
Sourcepub fn on_conflict(self, target: ConflictTarget) -> Self
pub fn on_conflict(self, target: ConflictTarget) -> Self
Set the conflict target.
Sourcepub fn do_nothing(self) -> Self
pub fn do_nothing(self) -> Self
Set conflict action to DO NOTHING.
Sourcepub fn do_update<I, S>(self, cols: I) -> Self
pub fn do_update<I, S>(self, cols: I) -> Self
Set conflict action to DO UPDATE for specified columns (using EXCLUDED).
Sourcepub fn do_update_set(self, assignments: Vec<Assignment>) -> Self
pub fn do_update_set(self, assignments: Vec<Assignment>) -> Self
Set conflict action to DO UPDATE with specific assignments.
Sourcepub fn where_clause(self, condition: impl Into<String>) -> Self
pub fn where_clause(self, condition: impl Into<String>) -> Self
Add a WHERE clause for the update (PostgreSQL).
Sourcepub fn to_postgres_sql(&self) -> String
pub fn to_postgres_sql(&self) -> String
Generate PostgreSQL INSERT … ON CONFLICT SQL.
Sourcepub fn to_mysql_sql(&self) -> String
pub fn to_mysql_sql(&self) -> String
Generate MySQL INSERT … ON DUPLICATE KEY UPDATE SQL.
Sourcepub fn to_sqlite_sql(&self) -> String
pub fn to_sqlite_sql(&self) -> String
Generate SQLite INSERT … ON CONFLICT SQL.
Sourcepub fn to_mssql_sql(&self) -> String
pub fn to_mssql_sql(&self) -> String
Generate MSSQL MERGE statement.
Sourcepub fn to_sql(&self, db_type: DatabaseType) -> String
pub fn to_sql(&self, db_type: DatabaseType) -> String
Generate SQL for the specified database type.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Upsert
impl<'de> Deserialize<'de> for Upsert
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Upsert
Auto Trait Implementations§
impl Freeze for Upsert
impl RefUnwindSafe for Upsert
impl Send for Upsert
impl Sync for Upsert
impl Unpin for Upsert
impl UnwindSafe for Upsert
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