views:

976

answers:

4

What is the best way to interact with a database using Haskell? I'm accustomed to using some sort of ORM (Django's ORM, hibernate, etc.) and something similar would be nice when creating apps with HAppS.

Edit: I'd like to be free to choose from Postgresql MySql and SQLite as far as the actual databases go.

A: 

Have you looked through the database mapping and access packages at http://hackage.haskell.org/packages/archive/pkg-list.html#cat:Database

I haven't used them, so can't recommend any particular one. I also don't know what databases you are planning on using.

wnoise
Updated the question to list databases I'm interested in, but it shouldn't be much of a filtering criteria. I've looked through hackage a bit in the past, but I should probably crawl it again. I would like to hear from people with personal experience though.
rcreswick
+2  A: 

The library I have in mind is not an ORM, but it may still do what you want.

If you want something that makes your database accesses safe while integrating things into your program nicely then try out HaskellDB. It basically looks at your schema, generates some data structures, and then gives you type safe ways to query. It's been around for quite a while and the community opinion is that it's good and stable.

To use it, you'll need some underlying Haskell DB library like HSQL.

Good luck!

Jason Dagit
HaskellDB paper: www.cs.chalmers.se/~bringert/publ/haskelldb/haskelldb-db-2005.pdf
rcreswick
HaskellDB has the problem that it currently doesn't build with recent versions of GHC (6.8 or 6.10).
Erik Hesselink
+2  A: 

I actually very much like the approach of HAppS (HAppS-State) which allows you to forget about going through the marshalling/unmarshalling cludge of ORM and let's you simply use Haskell's data types.

eelco
+4  A: 

The reason that ORM libraries exist is that there is relative big difference between Objects in C# or Java and what you store in a database. This is not so much an issue in Haskell because:

  1. It does not have Objects
  2. Both databases and Haskell list have their inspiration in mathematical set theory, so the friction between them is a lot less than between databases and Objects.
tomjen