[Haskell-cafe] ANN: hesql

Christoph Bauer ich at christoph-bauer.net
Thu Nov 12 15:58:23 EST 2009


Hello,

sure, your program could use a database with HDBC. But I'll guess
(since you love static typing so much) you dislike formulating queries
in strings and to check the positions of your ?-placeholders and to
convert your values with fromSql/toSql. Maybe you would prefer
for your select query a list of tuples instead of a list of lists,
because your beloved pattern matching needs always a dummy case.

And here [1] is hesql... it's a preprocessor, which rewrites SQL-Queries
as haskell functions. You put all your SQL-Queries
  (for example

   verifyLogin login' password' =
      select1' Accountid, Login, RealName, Email from Account
        where (password is null or password  = md5(password')) and Lower(Login) = login'
             and not Locked;
    )
in a module (example/Account.hesql) and run

  $ hesql example/Account.hesql dbname=example

which will write example/Account.hs, the real haskell module.

It will generate code for a haskell function with the type:

verifyLogin :: Stmts -> String -> String 
    ->  IO (Maybe (Int, String, String, String))

(Ok, this is not quite correct. Check the README.)

And Of course my SQL-Parser is very incomplete. Hesql works only with
postgresql, etc, etc. So, please send me patches :-) Don't expect too much.

Christoph Bauer
  
[1] on hackageDB


More information about the Haskell-Cafe mailing list