Using SQLite to store data

SQLite is one of the most popular databases for compactly storing structured data. We will use the SQL binding for Haskell to store a list of strings.

Getting Ready

We must first install the SQLite3 database on our system. On Debian-based systems, we can issue the following installation command:

$ sudo apt-get install sqlite3

Install the SQLite package from cabal, as shown in the following command:

$ cabal install sqlite-simple

Create an initial database called test.db that sets up the schema. In this recipe, we will only be storing integers with strings as follows:

$ sqlite3 test.db "CREATE TABLE test (id INTEGER PRIMARY KEY, str text);"

How to do it…

  1. Import the relevant libraries, as shown in the following code:
    {-# LANGUAGE ...

Get Haskell Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.