Alexander Kotelnikov <sa...@myxomop.com> writes:

> Ok, let me ask it in another way. Is there a good way to access
> databases, mysql in particular, from haskell program?

Use HDBC or Takusen.  You can find them on hackage.  HDBC is fairly usable,
but you must write SQL queries by yourself or use some simple machinery
to construct queries.  I've written a bunch of helper functions to
construct queries as strings, e.g.:

> insert :: String -> [String] -> String -> String
> insert t = (++)                  .
>           (" INSERT " ++)       .
>           (" INTO "   ++)       .
>           (t ++)                .
>           (" (" ++) . (++ ") ") .
>           join ", "

> select :: [String] -> String -> String
> select = (++) . (" SELECT " ++) . join ", "

> from   :: [String] -> String -> String
> from   = (++) . (" FROM   " ++) . join ", "

In the end your query looks like:

> query' (select ["max(cheque)"] . from ["history"] $ ";"

In this way you avoid typical errors which emerge when you write simple
SQL query strings.  Though you don't get true static typing.

There are haskelldb and Takusen, which provide more elaborate way of
connecting to RDBMS, they demand more investigation though.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to