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

Janne Hellsten jjhellst at gmail.com
Sun Sep 30 09:38:15 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

 * *

Notable changes since the previous announcement:

- Better thought out module exports - this release makes it possible
to add user-defined FromField instances (see
https://github.com/nurpax/sqlite-simple/blob/master/test/UserInstances.hs)
- sqlite-simple was upgraded to use the latest direct-sqlite 2.2
- As part of the release, the Snap sqlite-simple plugin
snaplet-sqlite-simple was upgraded to the latest sqlite-simple.  See
http://hackage.haskell.org/package/snaplet-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!



More information about the Haskell mailing list