[Haskell-cafe] ORM for haskell?

Jochem Berndsen jochem at functor.nl
Fri Jul 3 05:28:14 EDT 2009

Chris Eidhof wrote:
> I've something working that sort of does this. You define your model in
> the following way:
> data User = User {name :: String, password :: String, age :: Int, post
> :: BelongsTo Post}
> data Post = Post {title :: String, body :: String}
> Then there's some boilerplate code (that ultimately will be generated by
> TH), and from that moment on you can do things like this:
> test = do
>   conn <- connectSqlite3 "example.sqlite3"
>   runDB conn $ do
>     user <- fromJust <$> find typeUser 1
>     user' <- fillBelongsTo user relPost
>     return (post user')

> By default, no relations will be fetched, but by doing the fillBelongsTo
> the user will be updated. I currently have support for new, update and
> find. All of this code is very alpha, and only works using HDBC and
> Sqlite3, but still.

So in this example, both user and user' are of type User, but if I ask
for "post user", this is undefined?
I have done something similar as you, except that I filled the related
field with an unsafePerformIO fetching the related data from the database.


Jochem Berndsen | jochem at functor.nl

More information about the Haskell-Cafe mailing list