pub struct Upsert {
pub target: UpsertTarget,
pub shared: Assignments,
pub defaults: Assignments,
pub update_defaults: Assignments,
pub create: Assignments,
pub update: Assignments,
pub action: UpsertAction,
}Expand description
Conflict handling attached to an Insert.
The target selects one primary-key or unique-constraint conflict. Update
applies the normalized shared assignments to the matching
row, while Ignore leaves it unchanged.
Before normalization, shared,
defaults, update_defaults,
create, and update contain the
declarative assignments. The engine first routes update_defaults to any
branch without an explicit assignment. Normalization then writes the create
branch into the insert source, overlays the update branch onto shared, and
clears create and update. Defaults remain available to non-SQL drivers
and are cleared before SQL serialization. The engine also stores model-field
targets before lowering and database-column targets afterward. SQL drivers
receive the normalized, lowered form inside
Operation::QuerySql; non-SQL drivers
receive it inside Operation::Upsert.
Fields§
§target: UpsertTargetThe unique constraint that selects the conflicting row.
Assignments applied to both the create and update branches.
Normalization derives create values from these assignments and retains the assignments for conflict updates.
defaults: AssignmentsValues declared with #[default] on model fields.
These supply omitted create fields and initialize shared mutations. Explicit create assignments override them.
update_defaults: AssignmentsValues declared with #[update] on model fields.
Before verification, the engine routes each value to the create branch, update branch, or both according to which branches already have an explicit assignment.
create: AssignmentsAssignments applied only when the insert creates a record.
Explicit on_create assignments replace defaults and shared
assignments for the same field.
update: AssignmentsAssignments applied only when the target matches an existing record.
These override shared assignments for the same field and may reference
stored columns or fields projected from
ExprIncoming, the row proposed by the insert source.
action: UpsertActionWhether to update or ignore a conflicting row.