« Return to Thread: ORM for haskell?

Re: ORM for haskell?

by Chris Eidhof :: Rate this Message:

Reply to Author | View in Thread

Hey Marc,

On 30 jun 2009, at 19:52, Marc Weber wrote:

> Is there anyone interested in helping building a library which
> a) let's you define kind of model of you data
> b) let's you store you model in any backend (maybe a relational
>    database)
> c) does static checking of your queries at compilation time?
>
> [...]

> Maybe this does already exist and I've missed it?

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.

You can find and fork my code on http://github.com/chriseidhof/ 
generics. I'll be happy to answer any questions about the code or the  
ideas behind it.

-chris
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

 « Return to Thread: ORM for haskell?