[Haskell-cafe] ORM for haskell?
Marc Weber
marco-oweber at gmx.de
Tue Jun 30 18:14:34 EDT 2009
Hi Mads!
On Tue, Jun 30, 2009 at 11:49:40PM +0200, Mads Lindstrøm wrote:
> Hi Marc Weber
>
> > Another example: Updating the age of a pupil:
> >
> > row = SELECT * FROM pupils where age = 13;
> > UPDATE pupils SET age = 14 WHERE id = <the id you got above>
> >
> > p = session.query(Pupil).filter(Pupil.age==13).one().age=14
> > session.commit()
> >
> > difference?
> > You don't have to care about ids. you just assign a new value and
> > tell
> > the engine that it should commit.
> > So again less chances to get something wrong.
> >
>
> Could you not do in SQL:
>
> UPDATE pupils SET age = 14 WHERE age = 13
Of course.
But: you can pass around that pupil object to another function and still assign a new age
then run session.commit().
When passing around the pupile you can follow the relation_ships
(relations?) back to school.
def doSomething(pupil):
pupil['age'] = 13
pupil.teacher.school.rating += 1
doSomething(session.query(Pupil).filter(Pupil.age==13))
session.commit()
Now how would you do this using SQL?
Sorry about the confustion (relation / relation-ship). I mixed up the terminology.
Anyway I guess you can see here how powerful an ORM can be and why
we should write such a library for haskell.
I think it's very hard to invent such a short synax in haskell cause
you have to take monads into account etc..
And it matters how much time you have to spend writing code.
Thanks for your feedback. I hope there will be some more.
Marc Weber
More information about the Haskell-Cafe
mailing list