Persistence with Vapor using Postgres
We saw how we can build a REST API in Swift using the Vapor framework; however, this is of limited use on its own. To provide real utility, we need to store and retrieve our model so that it persists beyond the lifetime of the server.
A common approach is to use a relational database such as SQLite, MySql or Postgres, and Vapor, with support for a number of databases through the included Fluent
framework.
In this recipe, we will build on the REST API for tasks from the last recipe, and persist our model to a Postgres database. We'll choose Postgres because it is a popular relational database for which there is great support in Heroku, a hosting service we will use in the next recipe.
Getting started
For this recipe, we need to download, install, and run Postgres, and the easiest way to get Postgres is through the Homebrew package manager. We used Homebrew to install the Vapor CLI (Command-Line Interface), so it very likely that you already have Homebrew...