git.iko.soy/typeable/postgresql-simple
on master help sign in
Merge pull request #222 from tomjaguarpaw/json

Add fromFieldJSONByteString

commit8874189360dd5a3de3dae07977ff3e988fb2b5c3 authorLeon P Smith <leon.p.smith+github@gmail.com> dateSat 25 Nov 2017, 21:06 (9 years ago) parent70e19cd0d35b32
1 file changed+9−5
src/Database/PostgreSQL/Simple/FromField.hs+9−5
src/Database/PostgreSQL/Simple/FromField.hs+9−5
@@ -552,15 +552,19 @@ instance FromField UUID where
552552
553553-- | json
554554instance 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 =
556563 if typeOid f /= $(inlineTypoid TI.json) && typeOid f /= $(inlineTypoid TI.jsonb)
557564 then returnError Incompatible f ""
558565 else case mbs of
559566 Nothing -> returnError UnexpectedNull f ""
560− Just bs ->
561− case parseOnly (JSON.value' <* endOfInput) bs of
562− Left err -> returnError ConversionFailed f err
563− Right val -> pure val
567+ Just bs -> pure bs
564568
565569-- | Parse a field to a JSON 'JSON.Value' and convert that into a
566570-- Haskell value using 'JSON.fromJSON'.