Releases: vapor/sql-kit
Adds `ALTER _ RENAME TO _` support
This patch was authored by @NeedleInAJayStack and released by @0xTim.
Adds table-renaming support to SQLAlterTableBuilder
. This produces SQL queries of the form:
ALTER `table_name` RENAME TO `new_table_name`
Fix several issues with UNION query support
This patch was authored and released by @gwynne.
- Fixes
SQLUnionBuilder
lackingSQLQueryFetcher
conformance. - Fixes support for SQLite.
- Adds support for
INTERSECT [DISTINCT|ALL]
andEXCEPT [DISTINCT|ALL]
unions. - Adds documentation for
SQLDialect
and its subtypes. - Improves test infrastructure.
Add support for UNION queries
This patch was authored by @finestructure and released by @gwynne.
Adds support for UNION SELECT
queries:
try db.select()
.column("id")
.from("t1")
.where("f1", .equal, "foo")
.limit(1)
.union({
$0.column("id")
.from("t2")
.where("f2", .equal, "bar")
.limit(2)
}).union(all: {
$0.column("id")
.from("t3")
.where("f3", .equal, "baz")
.limit(3)
})
.run().wait()
Add support for `CREATE TABLE ... SELECT ...`
This patch was authored and released by @gwynne.
Adds SQLKit support for creating tables populated by SELECT
queries:
try await sqlDatabase.create(table: "populated")
.column("id", type: .bigint, .primaryKey, .notNull)
.column("data", type: .text)
.select { $0
.column(SQLLiteral.default, as: "id")
.column(SQLFunction("UPPER", args:
SQLFunction("LTRIM", args: SQLColumn("data"))
), as: "data")
.from("original_table")
.where("id", .in, Array(1 ... 10))
}
.run()
CREATE TABLE "populated" (
"id" BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"data" TEXT
) AS SELECT
DEFAULT AS "id",
UPPER(LTRIM("data")) AS "data"
FROM
"original_table"
WHERE
"id" IN ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
Additional changes:
- Significant internal reorganization of SQLKit, specifically in
SQLSelectBuilder
. - The
.where()
,.orWhere()
,.having()
, and.orHaving()
families of methods onSQLSelectBuilder
(and otherSQLPredicateBuilders
) have been normalized so that all four sets of methods offer the same series of overloads as all the others. - More
async
tests. - Support for MySQL's
DROP TEMPORARY TABLE
syntax, assqlDatabase.drop(table: "table").temporary()
.
Note: Despite what may seem appearances to the contrary, the public API of SQLSelectBuilder
has not lost any methods, though it has gained a small number of overloads. A concerted effort was made to avoid changing any existing API in any source-incompatible way.
Fix Swift compiler choosing wrong overload for SQLInsertBuilder.values(Encodable)
This patch was authored and released by @gwynne.
Under certain specific circumstances, the Swift compiler will choose the wrong overload of SQLInsertBuilder.values(_:)
for the variants that take Encodable
(specifically when an explicit Array is used in a generic context). Since it's too late to fix the API (it's public now), adding @_disfavoredOverload works around the issue in what should be a backwards-compatible fashion.
Add Concurrency extensions for SQLKit
This patch was authored and released by @gwynne.
Shockingly little effort required here! SQLKit doesn't do very much asynchronous work, in and of itself.
MySQL chokes on supplemental plane Unicode
This patch was authored and released by @gwynne.
So don't use it in the benchmarks. Sigh.
Support for UPSERT/conflict resolution clauses
This patch was authored and released by @gwynne.
Currently, the emitted syntax is compatible with SQLite and PostgreSQL, but not MySQL. Because MySQL diverges radically from the standard, considerable additional work would be needed to support it. Some design flaws still exist in this implementation, but it is possible to specify all of the common clauses needed for UPSERT
. There is no support for SQLite's ON CONFLICT ROLLBACK/ABORT/FAIL/IGNORE/REPLACE
syntax, nor for any of the more esoteric clauses supported by PostgreSQL. It doesn't seem useful to add that support; it's unlikely that a query requiring such specialized facilities would be portable across databases in any event.
Add convenience extensions to simplify some common use cases
This patch was authored and released by @gwynne.
I mean, I could go on adding methods like these to SQLKit for a week and not cover the entire API surface...
Adds methods to `orWhere` to match `where`
This patch was authored by @NeedleInAJayStack and released by @0xTim.
Adds additional missing methods to orWhere
that mirror where
. Specifically, it adds orWhere
methods for when the right-hand-side is:
- an encodable
- a list of encodables
- a column identifier
This allows for example
builder.orWhere("name", .equal, "Earth")