BSD-3-Clause licensed by Bryan O'Sullivan, Leon P Smith, Janne Hellsten
Maintained by Janne Hellsten

Module documentation for

There are no documented modules for this package.

sqlite-simple: mid-level bindings to the sqlite database

This library is a mid-level Haskell binding to the SQLite database.

Sqlite-simple provides a convenient API to sqlite that does some level of automatic data conversion between the database and Haskell types. The API has been modeled directly after postgresql-simple which in turn borrows from mysql-simple.

The sqlite-simple API reference contains more examples of use and information on its features.

The library is well tested and stable. The library should also be reasonably performant. You can find its benchmark suite here: db-bench. You can read more about sqlite-simple’s expected performance in my blog about sqlite-simple performance against direct-sqlite, Python and C.

Build Status


You can install sqlite-simple from Hackage with:

cabal install sqlite-simple

A Windows user? It works but please see this note on direct-sqlite Windows installation.

Examples of use

Create a test database by copy&pasting the below snippet to your shell:

sqlite3 test.db "CREATE TABLE test (id INTEGER PRIMARY KEY, str text);\
INSERT INTO test (str) VALUES ('test string');"

..and access it in Haskell:

{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import Database.SQLite.Simple
import Database.SQLite.Simple.FromRow

data TestField = TestField Int String deriving (Show)

instance FromRow TestField where
  fromRow = TestField <$> field <*> field

main :: IO ()
main = do
  conn <- open "test.db"
  execute conn "INSERT INTO test (str) VALUES (?)"
    (Only ("test string 2" :: String))
  r <- query_ conn "SELECT * from test" :: IO [TestField]
  mapM_ print r
  close conn

More simple usage examples can be found from sqlite-simple unit tests.


The development roadmap for sqlite-simple is mostly captured in the github issue database.

I’m happy to receive bug reports, fixes, documentation enhancements, and other improvements.

Please report bugs via the github issue tracker.

For general database issues with a Haskell focus, I recommend sending e-mail to the database-devel mailing list.


If you send pull requests for new features, it’d be great if you could also develop unit tests for any such features.


A lot of the code is directly borrowed from mysql-simple by Bryan O’Sullivan and from postgresql-simple by Leon P. Smith. Like Leon in postgresql-simple, I borrow code and documentation directly from both of these ancestor libraries.

This package builds on top of the direct-sqlite package by Irene Knapp.

SQLite is rather weakly-typed and thus the SQL to Haskell type strictness of the parent projects does not necessarily apply to this package.

* Add FromField instance for SQLData (thanks @LindaOrtega, @Shimuuar)
* Add QuasiQuoter sql (thanks @vrom911)
* Support GHC 8.4.1 (Add instance Semigroup Query) (thanks @gwils!)
* Use @hvr's Only package for the Only single element typle type.
* Add columnCount (thanks @Shimuuar!)
* Add withImmediateTransaction, withExclusiveTransaction (thanks @mbucc!)
* Expose the Database.SQLite3 Statement type through Database.SQLite.Simple Statement
* Add Setup.hs (
* Add queryWith
* Add executeMany
* Expose sqlite3_changes/total_changes
* Provide queryWith_ to allow more fine-grained access to
constructing queries.
* Expose error data constructors (pull request #42)
* Improve haddocks
* Export `bindNamed'
* Add `withTransaction' for running IO actions inside SQL
transactions with automated rollback if any exceptions are thrown.
* Fix unit test build break with older bytestring versions
* Add "named parameters" variants of query & al. Named params
allow queries like:
res <- queryNamed conn "SELECT * FROM posts WHERE id = :id" [":id" := postId]
* Add FromField instances for Int8, Word, Word8, Word16, Word32
and Word64.
* Fix typos in some type conversion error messages.
* Improved test coverage.
* Build fix for GHC 7.4
* Docs changes - uploaded new version to Hackage to update the
Hackage page.

* Various improvements to documentation. Especially UTCTime
parsing and printing, and how it relates to SQLite datetimes is
better documented now.

* Improved date/time parsing performance by adapting Leon
P. Smith's parsers from postgresql-simple for SQLite. UTCTime
handling is also better defined now.

* Improved query performance

* Improved tests for all areas touched by the above change.


* Add FromField instance for Float

* Improve error handling for day parsing

* + with tests

v0.4.1.0 - v0.4.3.0 (missed tagging v0.4.2.0)

* Improvements to withBind functionality and documentation

* Add columnName accessor for statements

* Expose MonadPlus on RowParser

* Allow access to the underlying direct-sqilte connection from an
sqlite-simple connection

* Add Data.Text.Lazy and lazy ByteString From/ToField instances


* Add lastInsertRowId

* Expose SQLite statements based streaming API


* Add fold, fold_, withConnection

v0.2.0.0 - v0.2.1.0

* Optimizations to improve query rows/sec performance
comments powered byDisqus