Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fromFieldJSONByteString #222

Merged
merged 1 commit into from Nov 26, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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'.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.