Protocol
SQLDialect
An abstract definition of a specific dialect of SQL.
protocol SQLDialect : Sendable
Overview
SQLKit uses the dialect provided by an instance of SQLDatabase to control various aspects of query serialization, with the intent of keeping SQLKit’s user-facing API from having to expose database-specific details as much as possible. While SQL dialects in the wild vary too widely in practice for this to ever be 100% effective, they also have enough in common to avoid having to rewrite every line of serialization logic for each database driver.
Topics
Basics
var name: StringThe name of the dialect.var identifierQuote: any SQLExpressionAn expression (usually anSQLRaw) giving the character(s) used to quote SQL identifiers, such as table and column names.var literalStringQuote: any SQLExpressionAn expression (usually anSQLRaw) giving the character(s) used to quote literal string values which appear in a query, such as enumerator names.func bindPlaceholder(at: Int) -> any SQLExpressionA function which returns an expression to be used as the placeholder for thepositionth bound parameter in a query.func literalBoolean(Bool) -> any SQLExpressionA function which returns an SQL expression (usually anSQLRaw) representing the given literal boolean value.var literalDefault: any SQLExpressionAn expression (usually anSQLRaw) giving the syntax used to express both “use this as the default value” in a column definition and “use the default value for this column” in a value list.
Support Flags
var supportsAutoIncrement: Booltrueif the dialect supports auto-increment for primary key values when inserting new rows,falseif not.var supportsIfExists: Booltrueif the dialect supports theIF EXISTSmodifier for all types ofDROPqueries (such asSQLDropEnum,SQLDropIndex,SQLDropTable, andSQLDropTrigger) and theIF NOT EXISTSmodifier forSQLCreateTablequeries.var supportsDropBehavior: Booltrueif the dialect supports thebehavior modifiers forDROPqueries,false` if not.var supportsReturning: Booltrueif the dialect supportsRETURNINGsyntax for retrieving output values from DML queries (INSERT,UPDATE,DELETE).var unionFeatures: SQLUnionFeaturesA set of feature flags describing the dialect’s support for various forms ofUNIONwithSELECTqueries.
Syntax Indicators
var enumSyntax: SQLEnumSyntaxThe syntax the dialect supports for strongly-typed enumerations.var triggerSyntax: SQLTriggerSyntaxVarious flags describing the dialect’s support for specific features ofSQLCreateTriggerandSQLDropTriggerqueries.var alterTableSyntax: SQLAlterTableSyntaxA description of the syntax the dialect supports forSQLAlterTablequeries.var autoIncrementClause: any SQLExpressionAn expression inserted in a column definition when a.primaryKey(autoincrement: true)constraint is specified for the column.var autoIncrementFunction: (any SQLExpression)?An expression inserted in a column definition when aSQLColumnConstraintAlgorithm.primaryKey(autoIncrement:)orSQLTableConstraintAlgorithm.primaryKey(columns:)constraint is specified for the column.var upsertSyntax: SQLUpsertSyntaxThe type ofUPSERTsyntax supported by the dialect.var sharedSelectLockExpression: (any SQLExpression)?A serialization forSQLLockingClause.share.var exclusiveSelectLockExpression: (any SQLExpression)?A serialization forSQLLockingClause.update.
Modifier Methods
func customDataType(for: SQLDataType) -> (any SQLExpression)?A function which is consulted whenever anSQLDataTypewill be serialized into a query. The dialect may return an expression which will replace the default serialization of the given type. Returningnilcauses the default to be used.func normalizeSQLConstraint(identifier: any SQLExpression) -> any SQLExpressionA function which is consulted whenever a constraint name will be serialized into a query. The dialect must return an expression for an identifer which is unique to the input identifier and is a valid constraint name for the dialect.func nestedSubpathExpression(in: any SQLExpression, for: [String]) -> (any SQLExpression)?Given a column name and a path consisting of one or more elements, return an expression appropriate for accessing a value at the given JSON path.
Relationships
Inherits From
Swift.SendableSwift.SendableMetatype
See Also
Drivers
protocol SQLDatabaseReportedVersionProvides a protocol for reporting and comparing database version numbers.struct SQLAlterTableSyntaxEncapsulates a dialect’s support forALTER TABLEsyntax.struct SQLTriggerSyntaxEncapsulates a dialect’s support forCREATE TRIGGERandDROP TRIGGERsyntax.struct SQLUnionFeaturesA set of feature support flags forUNIONqueries.enum SQLEnumSyntaxPossible values for a dialect’s strongly-typed enumeration support.enum SQLUpsertSyntaxThe supported syntax variants which a SQL dialect can use to to specify conflict resolution clauses.