[Haskell] ANNOUNCE: sqlite-simple 0.1.0.0: mid-level API to the sqlite database

Janne Hellsten jjhellst at gmail.com
Wed Aug 15 16:56:24 CEST 2012


sqlite-simple provides a convenient API to sqlite that performs
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 library is available on hackage at

  http://hackage.haskell.org/package/sqlite-simple

 * *

Example usage

First create a test database..

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

..and access it in Haskell:

---------------
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
---------------

 * *

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've borrowed code and documentation directly from
both of these ancestor libraries.

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

Thanks to all of the above for helpful comments, features and code
review.

 * *

Bugs, feature requests?

I'm happy to receive bug reports via github on:

  https://github.com/nurpax/sqlite-simple/issues

For discussion, I recommend the database-devel mailing list:

  http://www.haskell.org/mailman/listinfo/database-devel


Enjoy!

Janne



More information about the Haskell mailing list