hasql

hasql

Root of the "hasql" ecosystem. This library provides connection management, execution of queries and mapping of parameters and results. Extended functionality such as pooling, transactions and compile-time checking of SQL is provided by extension libraries. For more details and tutorials see the readme.

All error-reporting is explicit: database, protocol and connection failures are reported via the Either type instead of being thrown as exceptions.

The transport layer is pluggable via pqi, so "hasql" itself carries no C dependency. To compile an application you need to depend on "hasql" together with one adapter package and pass that adapter to Hasql.Connection.acquire as its first argument. Two adapters are available:

  • pqi-ffi - the stable, production-proven adapter, backed by the C "libpq" library. It requires "libpq" of at least version 14 to be installed to compile. "libpq" comes distributed with PostgreSQL, so typically all you need is just to install the latest PostgreSQL distro. Via this adapter "hasql" is thoroughly tested to be compatible with a wide range of PostgreSQL servers starting from version 9.
  • pqi-native - a pure-Haskell adapter, which speaks the PostgreSQL wire protocol directly and thus requires no C dependency at all. It is thoroughly tested: pqi-conformance runs it side by side with "libpq" on the same inputs and checks that the results agree, and the test-suites of "hasql", "hasql-pool" and "hasql-transaction" run against both adapters. It is still labelled alpha, but is fully interchangeable with "pqi-ffi": switching between the two is a one-line change.

Modules