Following installation methods are selectable
% sudo apt-get install haskell-relational-record
# zypper addrepo http://download.opensuse.org/repositories/devel:languages:haskell:lts:10/openSUSE_Tumbleweed/devel:languages:haskell:lts:10.repo # zypper refresh # zypper install ghc-relational-record-devel
% stack build relational-record
You may want to use LTS Haskell release of stackage. For example, command-line to build with LTS-11:
% stack --resolver lts-11 build relational-record
To start using Haskell Relational Record (HRR), you need to install:
- Glasgow Haskell Compiler (GHC) + the “cabal” command
- We recommend using the Haskell Platform
- The Haskell “relational-record” library
To install the Haskell “relational-record” library, run the following commands:
% cabal update % cabal install relational-record
Relational database system - In this quickstart, we assume that SQLite version 3 has been installed
In HRR, select statements are called relations. Let’s define our first relation. Copy the following to “hello.hs”:
hello defines our first relation. This “SELECT”s a constant tuple value (0,”Hello”) from the (virtual) empty table. In other words, this relation just returns (0,”Hello”).
Let’s run the above Haskell code to show what kind of SQL statement is generated:
OK. Next, let’s execute the SQL produced above in SQLite:
% runghc hello.hs | sqlite3 dummy.db 0|Hello
We got “0|Hello”! Note that “dummy.db” is just a dummy file.
Next, let’s compose relations. Copy the following to “helloworld.hs”:
This code defines queries called
helloworld composes them by joining them on the first element of the tuples.
This code generates the following SQL statement:
Finally, let’s execute it in SQLite:
% runghc helloworld.hs | sqlite3 dummy.db 0|Hello|World!
Now we understand that relations are composable. Raw SQL does NOT have this feature. Moreover, relations are type safe. If our HRR code can be compiled by GHC, it always generates valid SQL statements.
The next step is to read the HRR tutorial.