Swiftpack.co - Package - vapor/sql-kit

Github

link
Stars: 81

Used By

Total: 0

Releases

Enum Support - 2020-01-22 02:44:38

Adds support for using SQL enums natively. There are three different levels of support:

  • typeName: Postgres-like, has CREATE TYPE ... AS ENUM syntax
  • inline: MySQL-like, has ENUM(...) data type
  • unsupported: SQLite-like, no enum support.

Supported enum syntax is available via SQLDialect.enumSyntax. This can be used to conditionally run code depending on database support.

A new test case SQLBenchmarker.testEnum has been added that tests the following on all three databases:

  • Create table with enum column
  • Add new value to enum
  • Drop value from enum

Note: Dropping enum values from Postgres-like DBs is not supported.

Here is the raw SQL output from the benchmark for each database:

SQLite

CREATE TABLE "planets"("id" BIGINT PRIMARY KEY, "name" TEXT NOT NULL, "type" TEXT NOT NULL) []
INSERT INTO "planets" ("name", "type") VALUES (?, 'smallRocky'), (?, 'gasGiant') ["Earth", "Jupiter"]
INSERT INTO "planets" ("name", "type") VALUES (?, 'dwarf') ["Pluto"]
DELETE FROM "planets" WHERE "type" = 'gasGiant' []
DROP TABLE "planets" []

Postgres

CREATE TYPE "planet_type" AS ENUM ('smallRocky', 'gasGiant') []
CREATE TABLE "planets"("id" BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "name" TEXT NOT NULL, "type" "planet_type" NOT NULL) []
INSERT INTO "planets" ("name", "type") VALUES ($1, 'smallRocky'), ($2, 'gasGiant') ["Earth", "Jupiter"]
ALTER TYPE "planet_type" ADD VALUE 'dwarf' []
INSERT INTO "planets" ("name", "type") VALUES ($1, 'dwarf') ["Pluto"]
DELETE FROM "planets" WHERE "type" = 'gasGiant' []
DROP TABLE "planets" []
DROP TYPE "planet_type" []

MySQL

Opening new connection to [IPv6]localhost/::1:3306
CREATE TABLE `planets`(`id` BIGINT PRIMARY KEY AUTO_INCREMENT, `name` TEXT NOT NULL, `type` ENUM('smallRocky', 'gasGiant') NOT NULL) []
INSERT INTO `planets` (`name`, `type`) VALUES (?, 'smallRocky'), (?, 'gasGiant') ["Earth", "Jupiter"]
ALTER TABLE `planets` MODIFY `type` ENUM('smallRocky', 'gasGiant', 'dwarf') []
INSERT INTO `planets` (`name`, `type`) VALUES (?, 'dwarf') ["Pluto"]
DELETE FROM `planets` WHERE `type` = 'gasGiant' []
ALTER TABLE `planets` MODIFY `type` ENUM('smallRocky', 'dwarf') []
DROP TABLE `planets` []

Moved https://github.com/vapor/sql-kit/pull/83 here.

SQLKit 3.0.0 Beta 3 - 2019-12-13 22:03:46

  • Added new SQLRow.decode(model:) method (#79)
  • SQLRow protocol expanded to support Codable (#79)
  • Added first(decoding:) all(decoding:) and run(decoding:) methods to SQLQueryFetcher (#79)
  • Added set(model:) method to SQLUpdateBuilder (#79)

SQLKit 3.0.0 Beta 2 - 2019-12-09 17:21:12

  • Adds support for passing custom Loggers (#73)
  • Adds general purpose table constraints (#62)
  • Changes to using SQL 92 standard not equal operator (#61)
  • SQLDialect protocol has been reworked to be non-mutating. SQLDatabase now carries a reference to its dialect. (#70)
  • Enabled test discovery on Linux (#78)

SQLKit 3.0.0 Beta 1 - 2019-10-24 20:41:43

  • SQLDialect can now suppress IF [NOT] EXISTS using the supportsIfExists option. (#68)
  • GROUP BY and HAVING are now supported. (#69)

SQLKit 3.0.0 Alpha 1.4 - 2019-10-10 17:27:13

  • Fixed a SQL syntax error in SELECT statements with multiple joins

SQLKit 3.0.0 Alpha 1.3 - 2019-08-14 17:53:05

New:

  • Added SQLDialect.literalDefault option for customizing default literal string

SQLKit 3.0.0 Alpha 1.2 - 2019-07-09 15:56:41

New:

  • Adds SQLInsertBuilder.model method.
  • Adds SQLQueryEncoder.

SQLKit 3.0.0 Alpha 1.1 - 2019-06-06 00:07:15

New:

  • Added SQLDataType.custom(SQLExpression)

SQLKit 3.0.0 Alpha 1 - 2019-06-04 01:08:06

More information on Vapor 4 alpha releases:

https://medium.com/@codevapor/vapor-4-alpha-1-releases-begin-94a4bc79dd9a

API Docs:

https://api.vapor.codes/sql-kit/master/SQLKit/index.html

SQL 2.3.2 - 2019-03-26 21:14:19

Fixed:

  • SQLInsertBuilder now sorts rows to ensure correct order.

SQL 2.3.1 - 2019-03-26 21:05:46

Fixed:

  • Silenced a Swift 5 warning. (#55)

SQL 2.3.0 - 2019-01-11 20:11:01

New:

  • Adds SQLDirection.null and SQLDirection.notNull for ordering by null values. (#49).

SQL 2.2.0 - 2018-10-31 21:18:11

New:

  • Adds a convenience method for using COALESCE. (#42, #43)
conn.select().column(.coalesce(.sum(\Planet.id), 0), as: "id_sum")...
SELECT COALESCE(SUM(`id`), 0) as `id_sum` ...

SQL 2.1.0 - 2018-09-20 15:17:25

New:

  • New SQLConnectable protocol. All SQL builder shortcuts will now correctly appear on both database connections and pools. (#35)
pool.select().all().from(Planet.self).run()
  • SQLError protocol. SQL implementations can now conform their errors to this protocol to provide developers with a general purpose way for detecting common SQL errors, like constraint errors. (#35).

  • limit(...) has been added to SQLSelectBuilder. (#35)

  • order(...) has been added to SQLSelectBuilder. (#35)

  • Several new conveniences like count(...), sum(...), etc have been added to SQLExpression. (#35)

  • New type-safe where(...)overloads have been added to SQLSelectBuilder that support both arrays and single values. (#35, #33)

builder.where(\Planet.type, .in, [.smallRocky, .gasGiant])
builder.where(\Planet.type, .notEqual, .gasGiant)
  • SQLSelectBuilder now supports adding a sub SELECT to the column list. (#35)
conn.select().all()
    .column { select in
        select.column(\Planet.id).from(Planet.self).limit(1)
    }
    .from(Galaxy.self)

SQL 2.0.2 - 2018-07-17 02:19:49

Fixed:

  • Added missing methods to SQLSelectExpression.

SQL 2.0.1 - 2018-07-16 23:25:20

Fixed:

  • CREATE INDEX no longer incorrectly serializes column names.

SQL 2.0.0 - 2018-07-16 23:14:33

Protocols:

  • The query structures this package exposes have been protocolized to allow for better support of custom SQL dialects. Instead of using concrete types like struct and enum, this package now exposes protocols defining SQL capabilities. Specific SQL dialects can now create custom implementations of these protocols with additional stored properties or methods for supporting native functionality.

No serializers:

  • Now that the query structures are protocolized, types can be responsible for serializing themselves. This greatly reduces the amount of code needed to serialize the SQL and keeps code organized.

New query builders:

  • This package now exposes helpers for building the various SQL queries. This is a great way to build lower level queries without needing to resort to SQL strings.
let users = conn.select()
    .all().from(User.self)
    .where(\User.name == "Vapor")
    .all(decoding: User.self)
print(users) // Future<[User]>

The above code would result in a SQL query like:

SELECT * FROM "users" WHERE "users"."name" = ?

See the updated documentation for more information: docs.vapor.codes/3.0/sql/getting-started/

And of course, check out the API docs for detailed information about the public API: api.vapor.codes/sql/latest/SQL/

SQL 2.0.0 Beta 3 - 2018-06-22 21:50:46

New:

  • Added SQLCreateIndex and SQLDropIndex queries (#16).
  • New SQLCreateIndexBuilder for creating indexes on your database (#16).
conn.create(index: "planets_idx", on: \Planet.name).unique().run()

note: There is unfortunately no SQL standard for the DROP INDEX query so each SQL driver will be implementing their own drop index builder with custom syntax.

SQL 2.0.0 Beta 1.0.1 - 2018-06-21 22:47:10

SQL 2.0.0 Beta 2 - 2018-06-21 22:46:27

Fixed:

  • Replaced SQLConflictResolution with SQLForeignKeyAction (#15).
  • == and != now check for nil (#13).

SQL 2.0.0 Beta 1 - 2018-06-19 22:41:16

New:

  • SQL data structs have been refactored to protocols. This allows for the various SQL flavors to implement custom data types capable of defining their own storage and serialization.

SQL 1.0.0 - 2018-04-23 20:23:37

Introducing SQL 1.0! 🎉 *️⃣ Build SQL queries in Swift. Extensible, protocol-based design that supports DQL, DML, and DDL.

Docs: https://docs.vapor.codes/3.0/sql/getting-started/

API Docs: https://api.vapor.codes/sql/latest/SQL

⚠️ This package is brand new and may still be subject to change as we work out the APIs. Keep an eye on the release notes.


This package has been moved here from the vapor/database-kit repo.

Milestone: 1.0.0