Lesson 41. Using databases in Haskell
After reading lesson 41, you’ll be able to
- Connect to a SQLite database from Haskell
- Translate SQL rows into Haskell data types
- Create, read, update, and delete database data with Haskell
In this lesson, you’ll learn how to work with databases when using Haskell. In particular, you’ll use the SQLite3 relational database management system (RDBMS) and the sqlite-simple Haskell library. You’ll explore this topic by building a command-line interface for a tool-lending library. This will require you to perform all of the essential CRUD tasks commonly associated with RDBMS use. The CRUD tasks are as follows:
- Create—Adding new data to the database
- Read—Querying the database for information
- Update—Modifying existing data in the database
- Delete—Removing data from the database
You’ll use the sqlite-simple library to interact with your database. sqlite-simple is a mid-level abstraction over the database, meaning that while many of the low-level connection details are abstracted away, you’ll still be writing a large amount of raw SQL queries. The most important abstraction that sqlite-simple helps with is transforming SQL queries into lists of Haskell data types.