I have a record and a FromRow instance for it but when I try to evaluate an action using that query in the REPL it just seems to hang. I've tried everything I can think of but maybe I'm missing something? The code, simplified:
-- MyModuleA.hs
data MyRow
= MyRow
{ _myRowRowId :: UUID
, _myRowOtherId :: UUID
, _myRowDescription :: Text
}
deriving (Eq, Generic, Show)
instance FromRow MyRow where
fromRow =
MyRow
<$> field
<*> field
<*> field
-- MyModuleB.hs
getMyRow :: Connection -> MyRowId -> IO (Maybe MyRow)
getMyRow conn rid = do
r <- query conn
[sql| select id, other_id, description from my_row where id = ? |] [rid]
case r of
[] -> pure $ Nothing
(r' : _) -> pure $ Just r'
But in the REPL...
λ\=> r <- getMyRow conn rid
Just hangs. I'm able to execute other similar IO actions from the REPL, but not this one for some reason. I've tried various incantations of the parameter list, annotations, etc... it's weird. The query works fine in raw SQL.
I did narrow this down to the FromRow instance for my type. It can return a value of type Value but it doesn't try to parse that if I try to give the value a type that has a FromJSON instance. Some reason this causes fromRow to hang.
I have a record and a
FromRow
instance for it but when I try to evaluate an action using that query in the REPL it just seems to hang. I've tried everything I can think of but maybe I'm missing something? The code, simplified:But in the REPL...
Just hangs. I'm able to execute other similar IO actions from the REPL, but not this one for some reason. I've tried various incantations of the parameter list, annotations, etc... it's weird. The query works fine in raw SQL.
Hm... it may have to do with one of the fields having a JSON column and the
parseJSON
failing.I did narrow this down to the
FromRow
instance for my type. It can return a value of typeValue
but it doesn't try to parse that if I try to give the value a type that has aFromJSON
instance. Some reason this causesfromRow
to hang.So the lesson here is to get your row and deserialize your JSON values in a separate computation.