Week 7 & 8
News
RC2 was tagged for all packages last week, and with it, NIO now handles all non-blocking async for Vapor! 🎉🎉🎉 If you want to know more about the impact of NIO, check out Tanner on Swift by Sundell and Week 5 of Vapor Nation. Many API docs were also released this week. API docs are less like the tutorial style you’d find at docs.vapor.codes and more like traditional docs you’d find for other libraries and frameworks.
New Features
Adds Ability To Execute Shell Commands
adds a new Process.execute method for executing shell commands.
let result = try Process.execute("echo", "hi")
print(result) /// "hi"
Simplify The Services System
Simplifies the service system and internal caching.
Use foundation base64 + async deprecations
- use foundation for base64 coding
- adds escape/unescape methods for base64 strings and data
MySQL Query Pipelining
MySQL now supports multiple queries being enqueued when one is still running
vapor/mysql#145
vapor/fluent#411
vapor/fluent#413
New SQL Query Operators
vapor/fluent#423
vapor/fluent#424
Adds Command To Revert Migrations
Use Environment For Command Line Arguments
- move to using the
Environment.commandLine
property for accessing CLI arguments. An improvement over using a statically available property that could create issues for projects with multiple applications. - Adds
runningServer
property. - Adds
asyncBoot
andasyncRun
methods to Application
Services and Database Connections Are Now Extendable
Extendable
is a protocol which allows you to store data on instances of the protocol.
DatabaseConnection
and Service
are now Extendable
. This will allow higher-level libraries to store things on a connection without resorting to global caches which may leak memory.
vapor/service#19 vapor/database-kit#19
Decoding Errors Result In 400 Response
NIO
HTTP Pipelining
HTTP pipelining is a relatively new technique that’s only supported by a couple browsers at the present, but it has huge potential for performance gains. You can find the benchmarks yielding around 3x performance gains in a comment a ways down the thread.
Discussion On Performance Improvements For HTTP
Vapor lost some performance when it switched to NIO, but optimizing NIO’s HTTP parser should improve that by a lot.
Discussion On flatMap
vs then
For Future Interaction
flatMap
comes from the functional programming world and is more technically correct, but then
is more consistent with other promise/future implementations. What do you think?
Community Contributions
Tests That A Date’s Milliseconds Are Persisted
Prevent Foreign Keys From Being Created Twice
Adds Microsecond Support To MySQL and PostgreSQL
vapor/mysql#141
vapor/postgresql#29
Release The First Awaiter When A Promise Gets Fulfilled
Console Can Now Parse Short Flags Properly
Fix DateMiddleWare cached timestamp return logic
@grundoon noted that timestamps were being cached and never recalculated.
Default Postgres Port to 5432 When Not Supplied
@0xTim simplified PSQL config by defaulting to the port most setups of PSQL will be using.
Fix a memory leak in PostgreSQLConnection
@MrMage -
PostgreSQLTableNameCache holds a PostgreSQLConnection future. Once that future is fulfilled, it strongly holds a reference to PostgreSQLConnection. That connection in turn holds the table name cache, so we have a reference cycle. This causes the table name cache and its connection to never get released. This is relevant when testing, if the tests are set up such that each test creates a new Database.
Avoid double encoding of query params when using FoundationClient [Vapor 2]
https://github.com/vapor/engine/pull/244
Remove an unused argument in PostgreSQLDatabase.init
@MrMage cleaned up PostgreSQLDatabase.init
Close a PostgreSQLConnection
’s channel on deinit
Fixing join mapping
Added connection string parsing for PostgreSQLDatabaseConfig
@pedantix enabled PostgreSQLDatabaseConfig
to be initialized with a PSQL URL. This is typically the format you’ll get your credentials in in you’re using a service like Heroku
Correctly fetch LAST_INSERT_ID() on model creation
@jseibert allows Fluent to handle MySQL’s LAST_INSERT_ID
Make BenchmarkTimestampable
care more about fractional-second parts
@MrMage made benchmarking more precise
if tanner.createdAt?.isWithin(seconds: 0.1, of: Date()) != true {
self.fail("timestamps should be current")
}
Use microsecond precision on new time and datetime columns
@MrMage made MySQL’s time types more precise
Made FluentError init method public
guard let id = model.id else {
throw FluentError(identifier: "noID", reason: "A model must have an ID to be connected to a pivot"
}
Created QueryBuilder.set method
@calebkleveter’s PR adds a .set(_:to:) method to the QueryBuilder type, allowing you to run SET queries on a model.
Player.query(on: request).filter(\.points == 10_000).set(\.rank, to: 10)
Adapt To Updates In Crypto
@pedantix updated the JWT package to work with the most recent updates to Crypto
Adding Group By
Made QueryBuilder.connection
Property Public
Export Async To Avoid An Import When Conforming To Fluent Protocols
Changes Default Connector In Name Of Pivot Table From ‘+’ To ‘_’
@abbasmousavi addressed an issue where the +
symbol was giving a few databases a hard time.
Check to see if path is a directory as well
@rafiki270 fixed a bug where requests were being intercepted by FileMiddleware
.
Articles
Caleb Kleveter On Moving From Vapor 2 -> Vapor 3 In Production At Skelpo
https://www.skelpo.com/blog/vapor2-to-vapor3/
How To Perform Fluent Queries
This tutorial is an introduction for how to perform simple filter/sort queries on a database using Vapor’s ORM, Fluent.
https://www.vaporforums.io/thread/37
How To Write Models Using Fluent
This tutorial will show you how to implement a simple user model, store it to the database, get it back from the database and pass it to the view.
https://medium.com/@martinlasek/tutorial-how-to-write-models-using-fluent-e9482d335a5f
Persisting Data In Vapor 3
In this tutorial, we will be covering how to connect to a relational database (both PostgreSQL and MySQL) and then storing data in it.
https://theswiftwebdeveloper.com/diving-into-vapor-part-2-persisting-data-in-vapor-3-c927638301e8
Talks
Tanner Nelson On Swift by Sundell
Tanner talks with John Sundell about NIO, where he sees the future of Vapor, his own background, the inspiration for Vapor 3, and more!
https://www.swiftbysundell.com/podcast/18