46 Database queries with Quill
After reading this lesson, you will be able to:
- Connect to a database and execute SQL queries asynchronously using the Quill library
- Match database tables to case classes
- Write code to generate and run queries to select, insert, update and delete records
After learned about the type Future, you’ll learn how to connect and asynchronously perform queries to a database using a popular library called Quill. In particular, you’ll discover how to start a test PostgreSQL database instance and connect to it. You’ll see how to execute SQL queries. You’ll master how to define case classes that match its tables, and write code that generates SQL queries to retrieve, insert, update, and delete its records. In the capstone, you’ll use a database to store the questions and user information for a quiz application.
46.1 Project Setup
Rather than creating an SBT project from scratch, let’s download a base project as your starting point: the following subsections provide instructions on how to do this.
46.1.1 Download the base project
First, you need to create an SBT project and download its external dependencies. Navigate to an empty folder and use the git command to download the base project for this lesson: