I'm trying to use Haskell for a database app, and, as usual for Haskell, I'm finding the lack of decent documentation a real pain.
HaskellDB looks like a nice, high level approach to using databases, and, despite the look of its main page, the project isn't dead. However, when running the tests, I get this:
Problem with FlatDB: user error (Couldn't load Database.HaskellDB.FlatDB.driver from package haskelldb-flat-0.10) Skipping FlatDB Problem with HSQL MySQL: user error (Couldn't load Database.HaskellDB.HSQL.MySQL.driver from package haskelldb-hsql-mysql-0.10) Skipping HSQL MySQL Problem with HSQL SQLite: user error (Couldn't load Database.HaskellDB.HSQL.SQLite.driver from package haskelldb-hsql-sqlite-0.10) Skipping HSQL SQLite Cases: 0 Tried: 0 Errors: 0 Failures: 0 Skipped databases: ["FlatDB","HSQL MySQL","HSQL SQLite"]
This is despite having followed the build instructions carefully. I don't even know if I'm doing the right thing with these tests -- they obviously require some configuration, which I think I've done right, but there is no README for running the tests. I've googled for the error, with no results (next step the mailing list, but it seems crazy that I can't even get this far without subscribing to a mailing list and bothering someone). Also, the test suite doesn't actually compile without a minor fix, which indicates that not many people are actively running these tests, so maybe this entire test suite is non-functional. Who knows?
So, I'll see if I can just use HSQL straight. Unfortunately, there is no real documentation or tutorial for HSQL, nothing in the sources that tells you how to do even a basic test -- the online tutorials are very old and don't seem to actually cover making a connection. I tried this as a test app:
import Database.HSQL.MySQL (connect)
import Database.HSQL
main = do
c <- connect "localhost" "my_db" "my_username" "my_password"
disconnect c
return ()
It compiles, but throws this extremely helpful exception:
*** Exception: (unknown)
So, I'm giving up for now. HaskellDB also appears to have an HDBC backend (HDBC being another lower level SQL library, like HSQL), so I'll try HDBC when I get the motivation. I want to know that I have libraries that basically work before I invest any time on this, and tests or basic examples are essential to finding this out. Unfortunately these things seem to be somewhat lacking.
OK, </rant>
Comments §
http://www.realworldhaskell.org/blog/
I'm not sure if they are still looking but at one point they were looking for previewers.
What version of haskelldb are you using?
I recommend you the one that live in hackage.haskell.org. Don't run the test. If your program connect with your db, then everything must be ok.
Good luck.
import Database.HSQL.MySQL (connect)
import Database.HSQL
import Control.Exception
main =
catchDyn (do
c <- connect "localhost" "my_db" "my_username" "my_password"
disconnect c
return ())
handler
where handler :: SqlError -> IO ()
handler err = print err
this is a good site for HDBC and it works good.
Also the error "Exception unknown" may be because you create a table already created or read from nowhere etc.