[Haskell-cafe] Using HaskellDb to connect to PostgresSql

Justin Bailey jgbailey at gmail.com
Wed Mar 19 15:32:46 EDT 2008

On Wed, Mar 19, 2008 at 10:55 AM, Marc Mertens <marc.lisp at gmail.com> wrote:
> Hello,
>      I'm trying to learn to use HaskellDb. I have managed to finally compile and
>  install it on my linux box (I have ghc 6.8.2). But when I try to create a
>  database description (as described in
>  http://haskelldb.sourceforge.net/getting-started.html) (using DBDirect-dynamic
>  instead of DBDirect) I'm stuck. I have tried different names for the driver but

I don't have much information about using DBDynamic, but I am able to
connect to PostgreSQL easily. I have done it on Windows using GHC
6.8.2. I am using hdbc-postgresql, since hsql would not compile on
Windows for me. Here are the import statements and the login function
I have for a simple program that connects to postgresql and writes out
table info:

import Database.HaskellDB.DBSpec.DatabaseToDBSpec
import Database.HaskellDB.DBSpec.DBSpecToDBDirect
import Database.HaskellDB.Database
import Database.HaskellDB.HDBC.PostgreSQL
import Database.HaskellDB.PrimQuery
import Database.HaskellDB.FieldType
import Database.HaskellDB.DBSpec

login :: MonadIO m => String -> Int -> String -> String -> String ->
(Database -> m a) -> m a
login server port user password dbname = postgresqlConnect [("host", server),
  ("port", show port),
  ("user", user),
  ("password", password),
  ("dbname", dbname)]

The versions of all packages I'm using are:


Note you might have to modify the haskelldb cabal files to get them to
use later versions of HDBC.

As for recent documentation, unfortunately the darcs repository and
the code is the best place to go. The haddock documentation doesn't
have everything.

Finally, I'd suggest joining the haskell-db users mailing list for
specific questions. You can find info about that and the darcs
repository on the homepage at http://haskelldb.sourceforge.net.


More information about the Haskell-Cafe mailing list