[Haskell-cafe] Using HaskellDb to connect to PostgresSql

Bjorn Bringert bjorn at bringert.net
Sat Mar 22 18:57:04 EDT 2008


On Wed, Mar 19, 2008 at 8:32 PM, Justin Bailey <jgbailey at gmail.com> wrote:
> 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:
>
>   HDBC-1.1.4
>   HDBC-postgresql-1.1.4.0
>   haskelldb-hdbc-0.10
>   haskelldb-hdbc-postgresql-0.10
>
>  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.
>
>  Justin

Just to add to what Justin said, try using DBDirect-hdbc-postgresql
instead of DBDirect-dynamic. The "dynamic" driver adds an extra layer
of problems, and I'm not sure that it (or hs-plugins?) has been
updated to work with GHC 6.8.2. Because of a typo in a .cabal file,
there was no DBDirect-hdbc-postgresql until a few minutes ago, but if
you pull down the current darcs version and reinstall
haskelldb-hdbc-postgresql you should get it.

The HaskellDB documentation really is in a sorry state. Does anybody
feel like adding a wiki page with a basic getting-started HaskellDB
tutorial? It would be very appreciated. This page seems to contain
mostly meta-information:
http://www.haskell.org/haskellwiki/Applications_and_libraries/Database_interfaces/HaskellDB

/Björn


More information about the Haskell-Cafe mailing list