git.iko.soy/typeable/postgresql-simple
on master help sign in
Merge pull request #151 from srijs/fix/fromfield-value
2e09b1dLeon P Smith
src/Database/PostgreSQL/Simple/FromField.hs+3−8
@@ -112,10 +112,11 @@ module Database.PostgreSQL.Simple.FromField
112
112
113#include "MachDeps.h"
113#include "MachDeps.h"
114
114
115−import Control.Applicative ( (<|>), (<$>), pure, (*>) )
115+import Control.Applicative ( (<|>), (<$>), pure, (*>), (<*) )
116import Control.Concurrent.MVar (MVar, newMVar)
116import Control.Concurrent.MVar (MVar, newMVar)
117import Control.Exception (Exception)
117import Control.Exception (Exception)
118import qualified Data.Aeson as JSON
118import qualified Data.Aeson as JSON
119+import qualified Data.Aeson.Parser as JSON (value')
119import Data.Attoparsec.ByteString.Char8 hiding (Result)
120import Data.Attoparsec.ByteString.Char8 hiding (Result)
120import Data.ByteString (ByteString)
121import Data.ByteString (ByteString)
121import qualified Data.ByteString.Char8 as B
122import qualified Data.ByteString.Char8 as B
@@ -545,13 +546,7 @@ instance FromField JSON.Value where
545 else case mbs of
546 else case mbs of
546 Nothing -> returnError UnexpectedNull f ""
547 Nothing -> returnError UnexpectedNull f ""
547 Just bs ->
548 Just bs ->
548−#if MIN_VERSION_aeson(0,6,3)
549+ case parseOnly (JSON.value' <* endOfInput) bs of
549− case JSON.eitherDecodeStrict' bs of
550−#elif MIN_VERSION_bytestring(0,10,0)
551− case JSON.eitherDecode' $ LB.fromStrict bs of
552−#else
553− case JSON.eitherDecode' $ LB.fromChunks [bs] of
554−#endif
555 Left err -> returnError ConversionFailed f err
550 Left err -> returnError ConversionFailed f err
556 Right val -> pure val
551 Right val -> pure val
557
552
test/Main.hs+2
@@ -184,6 +184,8 @@ testJSON TestEnv{..} = TestCase $ do
184 roundTrip (Map.fromList [("foo","bar"),("bar","baz"),("baz","hello")] :: Map Text Text)
184 roundTrip (Map.fromList [("foo","bar"),("bar","baz"),("baz","hello")] :: Map Text Text)
185 roundTrip (Map.fromList [("fo\"o","bar"),("b\\ar","baz"),("baz","\"value\\with\"escapes")] :: Map Text Text)
185 roundTrip (Map.fromList [("fo\"o","bar"),("b\\ar","baz"),("baz","\"value\\with\"escapes")] :: Map Text Text)
186 roundTrip (V.fromList [1,2,3,4,5::Int])
186 roundTrip (V.fromList [1,2,3,4,5::Int])
187+ roundTrip ("foo" :: Text)
188+ roundTrip (42 :: Int)
187 where
189 where
188 roundTrip :: ToJSON a => a -> Assertion
190 roundTrip :: ToJSON a => a -> Assertion
189 roundTrip a = do
191 roundTrip a = do