Skip to content

Releases: vapor/sql-kit

Fix several issues with UNION query support

14 Dec 00:14
9cc30f8
Compare
Choose a tag to compare
This patch was authored and released by @gwynne.
  • Fixes SQLUnionBuilder lacking SQLQueryFetcher conformance.
  • Fixes support for SQLite.
  • Adds support for INTERSECT [DISTINCT|ALL] and EXCEPT [DISTINCT|ALL] unions.
  • Adds documentation for SQLDialect and its subtypes.
  • Improves test infrastructure.

Add support for UNION queries

06 Dec 07:35
d2027b4
Compare
Choose a tag to compare
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 ...`

01 Dec 19:02
bfcaa63
Compare
Choose a tag to compare
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 on SQLSelectBuilder (and other SQLPredicateBuilders) 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, as sqlDatabase.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)

27 Nov 00:58
1a788f4
Compare
Choose a tag to compare
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

20 Nov 23:50
dff8aba
Compare
Choose a tag to compare
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

22 Oct 13:46
8587674
Compare
Choose a tag to compare
This patch was authored and released by @gwynne.

So don't use it in the benchmarks. Sigh.

Support for UPSERT/conflict resolution clauses

22 Oct 12:57
64eff0a
Compare
Choose a tag to compare
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

14 Oct 12:36
8016882
Compare
Choose a tag to compare
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`

21 Jul 12:41
b70d1fe
Compare
Choose a tag to compare
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")

Adds '*' support for table-qualified column select

30 Jun 10:08
dd87127
Compare
Choose a tag to compare
This patch was authored by @NeedleInAJayStack and released by @0xTim.

This adds '*' support to table-qualified columns in selects that mirrors the non-table-qualified column selects. This is mainly a convenience.

For example, before this PR sql.select().column(table: "table", column: "*") would resolve to SELECT `table`.`*` , where '*' was an identifier which was invalid in most cases. Now it will resolve to SELECT `table`.*

Previously to make this query work, it would have to be sql.select().column(SQLColumn(SQLLiteral.all, table: SQLIdentifier("table")), which is kind of cumbersome.