Swiftpack.co - Package - vapor/sql

Github

link
Stars: 66
Help us keep the lights on

Dependencies

Releases

2.2.0 - Oct 31, 2018

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` ...

2.1.0 - Sep 20, 2018

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)

2.0.2 - Jul 17, 2018

Fixed:

  • Added missing methods to SQLSelectExpression.

2.0.1 - Jul 16, 2018

Fixed:

  • CREATE INDEX no longer incorrectly serializes column names.

2.0.0 - Jul 16, 2018

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/