[Haskell-beginners] Better way to retrieve data strucures from sql-db?
Hi Roman,
Template Haskell should be the preferred way to
cope with these "boilerplate" code problems.
Template Haskell: http://www.haskell.org/haskellwiki/Template_Haskell
Note: I'm a beginner myself so please wait for a more informed response.
Paolo
2009/9/28 Roman Naumann
The following function converts the data read from an sql database to a player data structure.
toPlayer :: [SqlValue] -> Player toPlayer sx = Player { plID = fromSql (sx!!0), plAccount = fromSql (sx!!1), plForename = fromSql (sx!!2), plSurename = fromSql (sx!!3), plPos_x = fromSql (sx!!4), plPos_y = fromSql (sx!!5) }
It appears to me, that I have to write this boilerplate code every time I introduce a new data structure that has to be read from the sql database. Can you think of a way to automate this?
Thanks for your replies, Roman Naumann
participants (1)
-
Paolo Losi