Skip to content

Package

SQLKit

SQLKit is a library for building and serializing SQL queries in Swift.

Overview

SQLKit’s query construction facilities provide mappings between Swift types and database field types, and a direct interface for executing SQL queries. It attempts to abstract away the many differences between the various dialects of SQL whenever practical, allowing users to construct queries for use with any of the supported database systems. Custom SQL can be directly specified as needed, such as when abstraction of syntax is not possible or unimplemented.

Note

Having been originally designed as a low-level “construction kit” for the Fluent ORM, the current incarnation of SQLKit is often excessively verbose, and offers relatively few user-friendly APIs. A future major release of Fluent is expected to replace both packages with an API designed around the same concepts as SQLKit, except targeted for both high-level and low-level use.

SQLKit does not provide facilities for creating or managing database connections; this functionality must be provided by a separate driver package which implements the required SQLKit protocols.

Topics

Fundamentals

Data Access

  • protocol SQLDatabase
    The common interface to SQLKit for both drivers and client code.
  • protocol SQLRow
    Represents a single row in a result set returned from an executed SQL query.
  • struct SQLRowDecoder
    An implementation of Decoder designed to decode “models” (or, in general, aggregate Decodable types) from SQLRows returned from a database query.
  • struct SQLQueryEncoder
    An implementation of Encoder designed to encode “models” (or, in general, aggregate Encodable types) into a form which can be used as input to a database query.

Drivers

Builder Protocols

Query Builders

Syntactic Expressions

  • struct SQLBinaryExpression
    A fundamental syntactical expression - a left and right operand joined by an infix operator.
  • enum SQLBinaryOperator
    SQL binary expression operators.
  • struct SQLBind
    A parameterizied value bound to the SQL query.
  • struct SQLFunction
    A call to a function available in SQL, expressed as a name and a (possibly empty) list of arguments.
  • struct SQLGroupExpression
    A fundamental syntactical expression - an arbitrary expression or list of expressions, surroudned by parenthesis.
  • struct SQLIdentifier
    A fundamental syntactical expression - a quoted identifier (also often referred to as a “name” or “object name”).
  • struct SQLList
    A fundamental syntactical expression - a list of subexpresions with a specified “separator” subexpression.
  • enum SQLLiteral
    A fundamental syntactical expression - one of several various kinds of literal SQL expressions.
  • struct SQLRaw
    A fundamental syntactical expression - an arbitrary string of raw SQL with no escaping or formating of any kind.

Basic Expressions

  • struct SQLAlias
    Encapsulates SQL’s <expression> [AS] <name> syntax, most often used to declare aliaed names for columns and tables.
  • struct SQLBetween
    An SQLExpression which constructs SQL of the form <operand> BETWEEN <lowerBound> AND <upperBound>.
  • struct SQLColumn
    An expression representing an optionally table-qualified column in an SQL table.
  • struct SQLConstraint
    An expression representing the combination of a constraint name and algorithm for table constraints.
  • enum SQLDataType
    Represents a value’s type in SQL.
  • enum SQLDirection
    Describes an ordering direction for a given sorting key.
  • struct SQLDistinct
    An expression representing the subexpression of an aggregate function call which specifies whether the aggregate groups over all result rows or only distinct rows.
  • enum SQLForeignKeyAction
    An expression specifying a behavior for a foreign key constraint violation.
  • struct SQLNestedSubpathExpression
    A “nested subpath” expression is used to descend into the “deeper” structure of a non-scalar value, such as a dictionary, array, or JSON value.
  • struct SQLQualifiedTable
    An expression representing an optionally second-level-qualified SQL table.
  • struct SQLQueryString
    An expression consisting of an array of constituent subexpressions generated by custom string interpolations.

Clause Expressions

Query Expressions

  • struct SQLAlterEnum
    An expression representing an ALTER TYPE query. Used to add new cases to enumeration types.
  • struct SQLAlterTable
    An expression representing an ALTER TABLE query. Used to modify the structure of existing tables.
  • struct SQLCreateEnum
    An expression representing a CREATE TYPE query. Used to create enumeration types.
  • struct SQLCreateIndex
    An expression representing a CREATE INDEX query. Used to add indexes over columns to an existing table.
  • struct SQLCreateTable
    An expression representing a CREATE TABLE query. Used to create new tables.
  • struct SQLCreateTrigger
    An expression representing a CREATE TRIGGER query. Used to create new triggers for actions on a table.
  • struct SQLDelete
    An expression representing a CREATE TRIGGER query. Used to remove rows from a table.
  • struct SQLDropEnum
    An expression representing a DROP TYPE query. Used to delete enumeration types.
  • struct SQLDropIndex
    An expression representing a DROP INDEX query. Used to delete indexes from tables.
  • struct SQLDropTable
    An expression representing a DROP TABLE query. Used to delete entire tables.
  • struct SQLDropTrigger
    An expression representing a DROP TRIGGER query. Used to delete triggers.
  • struct SQLInsert
    An expression representing an INSERT query. Used to add new rows to a table.
  • struct SQLSelect
    An expression representing a SELECT query. Used to retrieve rows and expression results from a database.
  • struct SQLUnion
    An expression representing two or more SELECT queries joined by UNION clauses. Used to merge the results of multiple queries into a single result set.
  • struct SQLUpdate
    An expression representing an UPDATE query. Used to modify existing rows in a single table.

Miscellaneous

  • struct SomeCodingKey
    A straightforward implementation of CodingKey, used to represent arbitrary keys.

Deprecated

Extended Modules