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

Now that you’ve learned about the type Future, you’ll discover how to connect and asynchronously perform queries to a database using a popular library called Quill. In particular, you’ll see 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 correspond to their tables and write code that generates SQL queries to retrieve, insert, update, and delete their 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.

46.1.1 Download the base project

46.1.2 Starting the PostgreSQL server

46.2 Connecting to the PostgreSQL server

46.3 Executing queries

46.4 Running generated queries

Summary

Answers to quick checks