[Haskell-beginners] SQLite3 Row <-> Data models -- Is this a typical Haskell pattern ?

Stef T stef at ummon.com
Sun Mar 20 01:21:56 CET 2011

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 ;

    name myBrandModel

    Thanks for reading this far, feel free to complain about my design :D

More information about the Beginners mailing list