Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 OverloadedStrings #-}
    import Control.Applicative
    import Database.SQLite.Simple
    import Database.SQLite.Simple.FromRow
  2. Create a FromRow typeclass implementation for TestField, the data type we will be storing, as shown in the following code:

    data...