git.iko.soy/typeable/postgresql-simple
on master help sign in
Add fromFieldJSONByteString
0d35b32Tom Ellis
src/Database/PostgreSQL/Simple/FromField.hs+9−5
@@ -552,15 +552,19 @@ instance FromField UUID where
552
552
553-- | json
553-- | json
554instance FromField JSON.Value where
554instance FromField JSON.Value where
555− fromField f mbs =
555+ fromField f mbs = parse =<< fromFieldJSONByteString f mbs
556+ where parse bs = case parseOnly (JSON.value' <* endOfInput) bs of
557+ Left err -> returnError ConversionFailed f err
558+ Right val -> pure val
559+
560+-- | Return the JSON ByteString directly
561+fromFieldJSONByteString :: Field -> Maybe ByteString -> Conversion ByteString
562+fromFieldJSONByteString f mbs =
556 if typeOid f /= $(inlineTypoid TI.json) && typeOid f /= $(inlineTypoid TI.jsonb)
563 if typeOid f /= $(inlineTypoid TI.json) && typeOid f /= $(inlineTypoid TI.jsonb)
557 then returnError Incompatible f ""
564 then returnError Incompatible f ""
558 else case mbs of
565 else case mbs of
559 Nothing -> returnError UnexpectedNull f ""
566 Nothing -> returnError UnexpectedNull f ""
560− Just bs ->
567+ Just bs -> pure bs
561− case parseOnly (JSON.value' <* endOfInput) bs of
562− Left err -> returnError ConversionFailed f err
563− Right val -> pure val
564
568
565-- | Parse a field to a JSON 'JSON.Value' and convert that into a
569-- | Parse a field to a JSON 'JSON.Value' and convert that into a
566-- Haskell value using 'JSON.fromJSON'.
570-- Haskell value using 'JSON.fromJSON'.