Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Database/PostgreSQL/Simple/FromField.hs
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,19 @@ instance FromField UUID where

-- | json
instance FromField JSON.Value where
fromField f mbs =
fromField f mbs = parse =<< fromFieldJSONByteString f mbs
where parse bs = case parseOnly (JSON.value' <* endOfInput) bs of
Left err -> returnError ConversionFailed f err
Right val -> pure val

-- | Return the JSON ByteString directly
fromFieldJSONByteString :: Field -> Maybe ByteString -> Conversion ByteString
fromFieldJSONByteString f mbs =
if typeOid f /= $(inlineTypoid TI.json) && typeOid f /= $(inlineTypoid TI.jsonb)
then returnError Incompatible f ""
else case mbs of
Nothing -> returnError UnexpectedNull f ""
Just bs ->
case parseOnly (JSON.value' <* endOfInput) bs of
Left err -> returnError ConversionFailed f err
Right val -> pure val
Just bs -> pure bs

-- | Parse a field to a JSON 'JSON.Value' and convert that into a
-- Haskell value using 'JSON.fromJSON'.
Expand Down