postgresql-binary 0.7.6 → 0.7.7
raw patch · 7 files changed
+82/−31 lines, 7 filesdep +json-astdep +rebasedep ~aesondep ~base-preludePVP ok
version bump matches the API change (PVP)
Dependencies added: json-ast, rebase
Dependency ranges changed: aeson, base-prelude
API changes (from Hackage documentation)
+ PostgreSQL.Binary.Decoder: jsonb :: Decoder Value
+ PostgreSQL.Binary.Encoder: jsonb :: Encoder Value
Files
- library/PostgreSQL/Binary/Decoder.hs +15/−1
- library/PostgreSQL/Binary/Encoder.hs +5/−0
- postgresql-binary.cabal +4/−2
- tasty/Main.hs +2/−0
- tasty/Main/Gens.hs +53/−2
- tasty/Main/PTI.hs +2/−1
- tasty/Main/Prelude.hs +1/−25
library/PostgreSQL/Binary/Decoder.hs view
@@ -3,7 +3,6 @@ Decoder, run, -- * Primitive- fn, int, float4, float8,@@ -15,9 +14,11 @@ text_lazy, char, -- * Misc+ fn, numeric, uuid, json,+ jsonb, -- * Time date, time_int,@@ -149,6 +150,19 @@ json :: Decoder Aeson.Value json = bytea_strict >>= either (BinaryParser.failure . fromString) pure . Aeson.eitherDecodeStrict'++{-# INLINABLE jsonb #-}+jsonb :: Decoder Aeson.Value+jsonb =+ fn $ (=<<) decode . getBytes+ where+ decode =+ mapLeft fromString .+ Aeson.eitherDecodeStrict'+ getBytes =+ maybe (Left "Empty input") Right .+ fmap snd .+ ByteString.uncons -- ** Textual
library/PostgreSQL/Binary/Encoder.hs view
@@ -17,6 +17,7 @@ numeric, uuid, json,+ jsonb, char, text_strict, text_lazy,@@ -229,6 +230,10 @@ Builder.lazyByteString . Aeson.encode #endif +{-# INLINABLE jsonb #-}+jsonb :: Encoder Aeson.Value+jsonb =+ \x -> "\1" <> json x -- * Text -------------------------
postgresql-binary.cabal view
@@ -1,7 +1,7 @@ name: postgresql-binary version:- 0.7.6+ 0.7.7 synopsis: Encoders and decoders for the PostgreSQL's binary format description:@@ -116,6 +116,8 @@ quickcheck-instances >= 0.3.11 && < 0.4, QuickCheck >= 2.8.1 && < 2.9, -- data:+ aeson,+ json-ast == 0.1.*, uuid == 1.3.*, time >= 1.4 && < 1.6, scientific >= 0.2 && < 0.4,@@ -131,7 +133,7 @@ conversion-text == 1.*, either == 4.*, transformers,- base-prelude,+ rebase >= 0.1.4 && < 0.2, base
tasty/Main.hs view
@@ -26,6 +26,8 @@ binary = testGroup "Binary format" [+ stdRoundtrip "jsonb" Gens.aeson PTI.jsonb Encoder.jsonb Decoder.jsonb+ , select "SELECT '1 year 2 months 3 days 4 hours 5 minutes 6 seconds 332211 microseconds' :: interval" (bool Decoder.interval_float Decoder.interval_int) (picosecondsToDiffTime (10^6 * (332211 + 10^6 * (6 + 60 * (5 + 60 * (4 + 24 * (3 + 31 * (2 + 12))))))))
tasty/Main/Gens.hs view
@@ -1,15 +1,19 @@ module Main.Gens where -import Main.Prelude hiding (assert, isRight, isLeft)-import Test.QuickCheck+import Main.Prelude hiding (assert, isRight, isLeft, choose)+import Test.QuickCheck hiding (vector) import Test.QuickCheck.Instances+import JSON.AST (JSON) import qualified Main.PTI as PTI import qualified Data.Scientific as Scientific import qualified Data.UUID as UUID import qualified Data.Vector as Vector+import qualified Rebase.Data.HashMap.Strict as HashMap import qualified PostgreSQL.Binary.Data as Data import qualified PostgreSQL.Binary.Encoder as Encoder import qualified Data.Text as Text+import qualified Data.Aeson as Aeson+import qualified JSON.AST -- * Generators@@ -18,6 +22,53 @@ auto :: Arbitrary a => Gen a auto = arbitrary++json :: Gen JSON+json =+ byDepth 0+ where+ byDepth depth =+ frequency (primitives <> composites)+ where+ primitives =+ map (freq,) [null, bool, number, string]+ where+ freq =+ maxFreq+ composites =+ map (freq,) [array, object]+ where+ freq =+ maxFreq - depth+ maxFreq =+ 6+ null =+ pure JSON.AST.Null+ bool =+ fmap JSON.AST.Bool arbitrary+ number =+ fmap JSON.AST.Number arbitrary+ string =+ fmap JSON.AST.String text+ array =+ fmap JSON.AST.Array (vector (byDepth (succ depth)))+ object =+ fmap JSON.AST.Object (hashMap text (byDepth (succ depth)))++vector :: Gen a -> Gen (Vector a)+vector element =+ join $ Vector.replicateM <$> arbitrary <*> pure element++hashMap :: (Eq a, Hashable a) => Gen a -> Gen b -> Gen (HashMap a b)+hashMap key value =+ fmap HashMap.fromList $ join $ replicateM <$> arbitrary <*> pure row+ where+ row =+ (,) <$> key <*> value++aeson :: Gen Aeson.Value+aeson =+ fmap unsafeCoerce json postgresInt :: (Bounded a, Ord a, Integral a, Arbitrary a) => Gen a postgresInt =
tasty/Main/PTI.hs view
@@ -1,6 +1,6 @@ module Main.PTI where -import BasePrelude hiding (bool)+import Main.Prelude hiding (bool) import qualified Database.PostgreSQL.LibPQ as LibPQ @@ -48,6 +48,7 @@ int8range = mkPTI 3926 (Just 3927) interval = mkPTI 1186 (Just 1187) json = mkPTI 114 (Just 199)+jsonb = mkPTI 3802 (Just 3807) line = mkPTI 628 (Just 629) lseg = mkPTI 601 (Just 1018) macaddr = mkPTI 829 (Just 1040)
tasty/Main/Prelude.hs view
@@ -15,7 +15,7 @@ -- base-prelude --------------------------import BasePrelude as Exports hiding (assert, Data, fail)+import Rebase.Prelude as Exports hiding (assert, Data, fail) -- transformers -------------------------@@ -29,30 +29,6 @@ import Conversion as Exports import Conversion.Text () import Conversion.ByteString ()---- bytestring---------------------------import Data.ByteString as Exports (ByteString)---- text---------------------------import Data.Text as Exports (Text)---- vector---------------------------import Data.Vector as Exports (Vector)---- scientific---------------------------import Data.Scientific as Exports (Scientific)---- uuid---------------------------import Data.UUID as Exports (UUID)---- time---------------------------import Data.Time as Exports -- placeholders -------------------------