
On Sat, Mar 19, 2011 at 7:21 PM, Stef T
Hey Everyone, Greetings, I am a total newb to haskell, so, I have a strange question (perhaps). Consider I have a data model which looks like this;
data Brand = Brand { id :: Int, name :: String, created_at :: String, updated_at :: String }
Now, I have a sqlite3 function such as
checkout :: Int -> IO (Either String [[Row Value]]) checkout a = do handle <- openConnection "/Users/stef/haskell/db/development.sqlite3" execStatement handle $ "SELECT * from brands where id = " ++ show a
From this, I get a Row/Tuple. So far, so good, but, the question _I_ have is, how do you go about mapping a returned row to the data model ? Is this even a design pattern that is used in FP languages ? I admit, I have spent numerous years in the MVC world, so, perhaps this is simply "not done". It would seem to be a much nicer thing to then do ;
What problem are you running into trying to do this? You would need to write functions to convert each column into the format you want it for the Brand type, and then pass output of the functions Brand data constructor. Depending on the format of the data and the library you're using these functions might turn out to be pretty simple. It's considered good in Haskell to get data out of "weak" types into specific types when you want them, as in from a String or from a 'Row Value' - it makes manipulations of the values easier to read and you get the compiler's help figuring things out. Which SQL library are you using?
name myBrandModel
Thanks for reading this far, feel free to complain about my design :D Regards S. _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners