selda: Multi-backend, high-level EDSL for interacting with SQL databases.

[ database, library, mit ] [ Propose Tags ]
This version is deprecated.

This package provides an EDSL for writing portable, type-safe, high-level database code. Its feature set includes querying and modifying databases, automatic, in-process caching with consistency guarantees, and transaction support. See the project website for a comprehensive tutorial. To use this package you need at least one backend package, in addition to this package. There are currently two different backend packages: selda-sqlite and selda-postgresql.

[Skip to Readme]


Automatic Flags

Enable process-local cache support. Even when supported, caching is turned off by default until enabled by the application. When unsupported, the relevant APIs are still available, but the cache will act as if every update is a no-op and every lookup a cache miss.


Automatically set when installing for the Haste compiler.


Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,,,,,,,,,,,,,,,,, 0.1.12,,,,,,,,,,,, (info)
Change log
Dependencies base (>=4.8 && <5), bytestring (>=0.10 && <0.11), exceptions (>=0.8 && <0.11), hashable (>=1.1 && <1.3), mtl (>=2.0 && <2.3), psqueues (>=0.2 && <0.3), text (>=1.0 && <1.3), time (>=1.5 && <1.10), transformers (>=0.4 && <0.6), unordered-containers (>=0.2.6 && <0.3) [details]
License MIT
Author Anton Ekblad
Category Database
Home page
Source repo head: git clone
Uploaded by AntonEkblad at 2018-08-07T17:45:17Z
Reverse Dependencies 4 direct, 1 indirect [details]
Downloads 15132 total (101 in the last 30 days)
Rating 2.5 (votes: 3) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-08-07 [all 1 reports]

Readme for selda-

[back to package description]


Join the chat at Hackage IRC channel MIT License Build Status Hackage Dependencies

What is Selda?

Selda is a Haskell library for interacting with SQL-based relational databases. It was inspired by LINQ and Opaleye.


  • Monadic interface.
  • Portable: backends for SQLite and PostgreSQL.
  • Generic: easy integration with your existing Haskell types.
  • Creating, dropping and querying tables using type-safe database schemas.
  • Typed query language with products, filtering, joins and aggregation.
  • Inserting, updating and deleting rows from tables.
  • Conditional insert/update.
  • Transactions, uniqueness constraints and foreign keys.
  • Seamless prepared statements.
  • Configurable, automatic, consistent in-process caching of query results.
  • Lightweight and modular: few dependencies, and non-essential features are optional or split into add-on packages.

Getting started

Install the selda package from Hackage, as well as at least one of the backends:

$ cabal update
$ cabal install selda selda-sqlite selda-postgresql

Then, read the tutorial. The API documentation will probably also come in handy.


Selda requires GHC 7.10+, as well as SQLite 3.7.11+ or PostgreSQL 9.6+. To build the SQLite backend, you need a C compiler installed. To build the PostgreSQL backend, you need the libpq development libraries installed (libpq-dev on Debian-based Linux distributions).



All forms of contributions are welcome!

If you have a bug to report, please try to include as much information as possible, preferably including:

  • A brief description (one or two sentences) of the bug.
  • The version of Selda+backend where the bug was found.
  • A step-by-step guide to reproduce the bug.
  • The expected result from following these steps.
  • What actually happens when following the steps.
  • Which component contains the bug (selda, selda-sqlite or selda-postgresql), if you're reasonably sure about where the bug is.

Bonus points for a small code example that illustrates the problem.

If you want to contribute code, please consult the following checklist before sending a pull request:

  • Does the code build with a recent version of GHC?
  • Do all the tests pass?
  • Have you added any tests covering your code?

Setting up the build environment

From the repository root:

  • Install libpq-dev from your package manager. This is required to build the PostgreSQL backend.
  • Run make sandbox followed by make deps. This will set up a local sandbox for your Selda hacking, and install all Haskell necessary dependencies.
  • Familiarise yourself with the various targets in the makefile. The dependencies between Selda, the backends and the tests are slightly complex, so straight-up cabal is too quirky for day to day hacking.

Setting up a VM for PostgreSQL testing

While the SQLite backend is completely self-contained, the PostgreSQL backend needs an appropriate server for testing. Setting this up in a virtual machine is definitely less intrusive than setting up a server on your development machine. To set up a VM for the PostgreSQL backend tests:

  • Install your favourite hypervisor, such as VMWare player or VirtualBox.
  • Download a pre-built PostgreSQL VM from Bitnami.
  • Import the OVA file into your hypervisor.
  • Change the network settings of your newly imported VM to NAT, and make sure that port 5432 is forwarded. Note that this will conflict with any PostgreSQL server running on your machine while the VM is running.
  • Boot your VM and note the password displayed on the login screen.
  • Create the file selda-tests/PGConnectInfo.hs with the following content:
    {-# LANGUAGE OverloadedStrings #-}
    module PGConnectInfo where
    import Database.Selda.PostgreSQL
    pgConnectInfo = "test" `on` "localhost" `auth` ("postgres", "$PASSWORD")
    Where $PASSWORD is the password from the VM's login screen.
  • Log in to the VM and disable the built-in firewall by running sudo systemctl disable ufw ; sudo systemctl stop ufw.
  • From your host machine, create the test database:
    $ psql -h -U postgres -W
    [password from login screen]
    # CREATE TABLE test;
    # \q
  • Run make pgtest to check that everything works.


Features that would be nice to have but are not yet implemented.

  • Monadic if/else.
  • Streaming
  • MySQL/MariaDB backend.
  • MSSQL backend.
  • Automatically sanity check changelog, versions and date before release.