Structure
SQLConflictResolutionStrategy
Specifies a conflict resolution strategy and associated conditions for an
INSERT query. An INSERT with a conflict strategy is often refered to as an UPSERT (“insert or update”). Databases are not required to support any given subset of upsert functionality, or any at all.struct SQLConflictResolutionStrategy
Overview
Unfortunately, in MySQL the “no action” strategy must use INSERT IGNORE, which appears in a completely different place in the query than the update strategy. For now, this is implemented by providing an additional expression that SQLInsert has to embed at the appropriate point if provided, which is gated on both the dialect’s syntax and the conflict action. There hasn’t been a need to deal with this particular kind of syntax issue before, so this method of handling it is something of an experiment.
Topics
Initializers
init(target:action:)Create a resolution strategy over the given column name and an action.init(targets:action:)Create a resolution strategy over the given column names and an action.
Instance Properties
actionAn action to take to resolve a conflict in the unique index.targetColumnsThe column or columns which comprise the uniquness constraint to which the strategy should apply. The exact rules for how a matching constraint is found when an exact match is not found vary between databases. Not all database implement conflict targets.
Instance Methods
queryModifier(for:)An expression to be embedded into the sameINSERTquery as the strategy expression to work around MySQL’s desire to make life difficult.serialize(to:)Invoked when a request is made to serialize the expression to raw SQL.
Relationships
Conforms To
SQLExpressionSwift.SendableSwift.SendableMetatype
See Also
Clause Expressions
SQLAlterColumnDefinitionTypeA clause specifying a new data type to be applied to an existing column.SQLColumnAssignmentEncapsulates acolumn_name=valueexpression in the context of anUPDATEquery’s value assignment list. This is distinct from anSQLBinaryExpressionusing the.equaloperator in that the left side must be an unqualified column name, the operator must be=, and the right side may useSQLExcludedColumnwhen the assignment appears in theassignmentslist of aSQLConflictAction.update(assignments:predicate:)specification.SQLColumnConstraintAlgorithmColumn-level data constraints.SQLColumnDefinitionA clause expressing a column definition, for use when creating and altering tables.SQLConflictActionAn action to take when anINSERTquery encounters a unique constraint violation.SQLDropBehaviorSpecifies a behavior when performing aDROPoperation on a database object which is referenced by other objects.SQLEnumDataTypeRepresents a data type which specifies an enumeration in the database.SQLExcludedColumnAn expression appearing on the right side of a column assignment which, when the assignment list is part of an upsert’s update acion, refers to the value which was originally to be inserted for the given column.SQLForeignKeyA completeFOREIGN KEYconstraint specification.SQLInsertModifierSimple helper for working around MySQL’s refusal to implement standard SQL. Only emits SQL when needed.SQLJoinEncapsulates a single SQLJOIN, specifying the join type, the right-side table, and condition.SQLJoinMethodThe method used by a table join clause.SQLLockingClauseAn SQL locking clause.SQLOrderByA pair of expressions, one describing a query sort key and the other a directionality for that key.SQLReturningA clause describing a list of values to be returned from a data-modifying query.