Enumeration
SQLColumnConstraintAlgorithm
Column-level data constraints.
enum SQLColumnConstraintAlgorithm
Overview
Most dialects of SQL support both column-level (specific to a single column) and table-level (applicable to a list of one or more columns within the table) constraints. While some constraints can be expressed either way, others are only allowed at the column level. See SQLTableConstraintAlgorithm for table-level constraints.
Column-level constraints typically do not have separate constraint names, and are thus not used in concert with SQLConstraint expressions except in unusual cases.
Column constraints are used primarily by SQLColumnDefinition, and also appear directly in the APIs of SQLAlterTableBuilder, SQLCreateIndexBuilder, and SQLCreateTableBuilder.
Topics
Enumeration Cases
case check(any SQLExpression)ACHECKcolumn constraint and its associated validation expression.case collate(name: any SQLExpression)ACOLLATEcolumn constraint, specifying a text collation.case custom(any SQLExpression)An arbitrary expression used in place of a defined constraint.case `default`(any SQLExpression)ADEFAULTcolumn constraint, specifying a default column value.case foreignKey(references: any SQLExpression)AFOREIGN KEYcolumn constraint, specifying the referenced data.case generated(any SQLExpression)AGENERATEDcolumn constraint and its associated data-generating expression.case notNullANOT NULLcolumn constraint.case primaryKey(autoIncrement: Bool)APRIMARY KEYconstraint, either with or without the auto-increment characteristic.case uniqueAUNIQUEcolumn constraint, also called a unique key.
Instance Methods
func serialize(to: inout SQLSerializer)Invoked when a request is made to serialize the expression to raw SQL.
Type Properties
static var primaryKey: SQLColumnConstraintAlgorithmEquivalent to.primaryKey(autoIncrement: true).
Type Methods
static func collate(name: String) -> SQLColumnConstraintAlgorithmEquivalent to.collate(name: SQLIdentifier(name)).static `default`(_:)Equivalent to.default(SQLLiteral.boolean(value)).static references(_:_:onDelete:onUpdate:)Specifies aFOREIGN KEYconstraint by individual parameters.
Relationships
Conforms To
SQLExpressionSwift.SendableSwift.SendableMetatype
See Also
Clause Expressions
struct SQLAlterColumnDefinitionTypeA clause specifying a new data type to be applied to an existing column.struct 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.struct SQLColumnDefinitionA clause expressing a column definition, for use when creating and altering tables.struct SQLCommonTableExpressionA clause describing a single Common Table Expressions, which in itws simplest form provides additional data to a primary query in the same way as joining to a subquery.struct SQLCommonTableExpressionGroupA clause representing a group of one or moreSQLCommonTableExpressions.enum SQLConflictActionAn action to take when anINSERTquery encounters a unique constraint violation.struct SQLConflictResolutionStrategySpecifies a conflict resolution strategy and associated conditions for anINSERTquery. AnINSERTwith a conflict strategy is often refered to as anUPSERT(“insert or update”). Databases are not required to support any given subset of upsert functionality, or any at all.enum SQLDropBehaviorSpecifies a behavior when performing aDROPoperation on a database object which is referenced by other objects.struct SQLEnumDataTypeRepresents a data type which specifies an enumeration in the database.struct 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.struct SQLForeignKeyA completeFOREIGN KEYconstraint specification.struct SQLInsertModifierSimple helper for working around MySQL’s refusal to implement standard SQL. Only emits SQL when needed.struct SQLJoinEncapsulates a single SQLJOIN, specifying the join type, the right-side table, and condition.enum SQLJoinMethodThe method used by a table join clause.enum SQLLockingClauseAn SQL locking clause.