How can i access the data that`s in my query [VarcharIntDate] ?
data VarcharIntDate = VarcharIntDate {
vc :: Maybe String,
i :: Maybe Int,
d :: Maybe Date
} deriving (Show)
instance FromRow VarcharIntDate where
fromRow = VarcharIntDate <$> field <*> field <*> field
I understand how to print it, but I cant do much else with it because I don`t understand how to treat 'IO [VarcharIntDate]'
print =<< ( query_ conn "select vc,i,d from varintdate" :: IO [VarcharIntDate] )
but what I want to do is access 'd' from the n'th row of the returned [VarcharIntDate] or 'i' from all rows, so I can start pulling the data out from the query and start working with it.
You actually already process the result of the
IO [VarcharIntDate]
. You use=<<
withprint
. This is equivalent to:You can process the result of
query_
by performing amap
ping, or accessing the n-th element of the row like:So here we can use
res!!p
to access thep
-th row, and then call thed
getter to obtain thed
of that row.If you want to obtain all
i
's you can usemap i
.