Gain an overview of what steps are necessary to incorporate a database into your Vapor project.
- When working with databases in Vapor, there are essentially three steps that you have to do to set your project up. First, you'll need to make sure that your database of choice is installed on your machine. In this course, we'll be using PostgreSQL. However, it's very easy to switch between other database solutions, such as MySQL or MongoDB with just a few lines of code, as you'll see later on in this course. Secondly, you'll need to add your Provider to your Vapor project.
To do this, you'll want to go to the Vapor GitHub page, search for your Provider, and copy the URL to its GitHub repository. Then, you're going to add it as a dependency to your Package.swift file. Lastly you want to add your database driver to your Vapor project, which you do in your main .swift file when you declare your Droplet. First, you're going to import your Provider. Then, when initializing your Droplet, you're going to add in a parameter for your database Provider.
Now that we have an understanding of the steps, let's go ahead and see this in action.
- Installing PostgreSQL
- Implementing a database provider and a database driver
- Working with data models
- Implementing functions such as reading, updating, and deleting persisted data
- Working with dynamic Leaf templates
- Handling authentication inside of Vapor
- Creating a login controller
- Securing certain routes within your web service
- Creating a RESTful interface