hasql-postgres 0.10.1 → 0.10.2
raw patch · 5 files changed
+42/−3 lines, 5 filesdep +aesondep ~base-preludePVP ok
version bump matches the API change (PVP)
Dependencies added: aeson
Dependency ranges changed: base-prelude
API changes (from Hackage documentation)
+ Hasql.Postgres: instance CxValue Postgres Value
Files
- CHANGELOG.md +6/−0
- hasql-postgres.cabal +4/−2
- hspec/Main.hs +14/−1
- library/Hasql/Postgres.hs +9/−0
- library/Hasql/Postgres/Mapping.hs +9/−0
CHANGELOG.md view
@@ -1,3 +1,9 @@+# 0.10.2+* JSON support++# 0.10.1+* Update the "backend" dependency+ # 0.10.0 - Major overhaul * Transactions now are only retried in case of the "serialization_failure" (40001) error
hasql-postgres.cabal view
@@ -1,7 +1,7 @@ name: hasql-postgres version:- 0.10.1+ 0.10.2 synopsis: A "PostgreSQL" backend for the "hasql" library description:@@ -81,6 +81,7 @@ postgresql-binary == 0.5.*, postgresql-libpq == 0.9.*, -- data:+ aeson >= 0.7 && < 0.9, uuid == 1.3.*, vector == 0.10.*, time >= 1.4 && < 1.6,@@ -99,7 +100,7 @@ loch-th == 0.2.*, placeholders == 0.1.*, -- general:- base-prelude >= 0.1.3 && < 0.2,+ base-prelude >= 0.1.13 && < 0.2, base >= 4.5 && < 4.8 @@ -150,6 +151,7 @@ quickcheck-instances == 0.3.*, QuickCheck == 2.7.*, -- data:+ aeson, vector == 0.10.*, old-locale == 1.0.*, time >= 1.4 && < 1.6,
hspec/Main.hs view
@@ -19,6 +19,7 @@ import qualified Data.Scientific as Scientific import qualified Data.Vector as Vector import qualified PostgreSQLBinary.Encoder as PBE+import qualified Data.Aeson as J type Text = Data.Text.Text@@ -28,7 +29,11 @@ type Scientific = Scientific.Scientific -main = +main = do+ version <-+ fmap (fst . last . readP_to_S parseVersion . Data.Text.unpack) $+ fmap (runIdentity . either (error . show) id) $+ session1 $ H.tx Nothing $ H.singleEx [H.stmt| SHOW server_version |] hspec $ do describe "Feature" $ do@@ -112,6 +117,14 @@ [H.stmt|select oid, typname from pg_type|] :: Session [(Word, Text)] describe "Mapping of" $ do++ when (version >= Version [9,2] []) $ describe "JSON" $ do++ it "encodes and decodes" $ do+ let v = (1, 'a') :: (Int, Char)+ json = J.toJSON v+ in flip shouldBe (Right (Identity json)) =<< do+ session1 $ H.tx Nothing $ H.singleEx [H.stmt| SELECT ($json :: json) |] describe "Enum" $ do
library/Hasql/Postgres.hs view
@@ -34,6 +34,7 @@ import qualified Language.Haskell.TH as TH import qualified Data.Text.Encoding as Text import qualified Data.Vector as Vector+import qualified Data.Aeson as J import qualified ListT @@ -480,6 +481,14 @@ -- | -- Maps to @uuid@. instance Bknd.CxValue Postgres UUID where+ encodeValue = encodeValueUsingMapping+ decodeValue = decodeValueUsingMapping++-- |+-- Maps to @json@.+-- +-- Only works for PostgreSQL versions >= 9.2.+instance Bknd.CxValue Postgres J.Value where encodeValue = encodeValueUsingMapping decodeValue = decodeValueUsingMapping
library/Hasql/Postgres/Mapping.hs view
@@ -8,9 +8,11 @@ import qualified Data.Vector as V import qualified Data.ByteString.Lazy as BL import qualified Data.Text.Lazy as TL+import qualified Data.Text as T import qualified PostgreSQLBinary.Array as Array import qualified PostgreSQLBinary.Encoder as Encoder import qualified PostgreSQLBinary.Decoder as Decoder+import qualified Data.Aeson as J -- |@@ -263,7 +265,14 @@ [|PTI.uuid|] [|const $ Encoder.uuid|] [|const $ Decoder.uuid|]+ ,+ (,,,)+ [t|J.Value|]+ [|PTI.json|]+ [|const $ Encoder.bytea . Right . J.encode|]+ [|const $ (>>= either (Left . T.pack) Right . J.eitherDecodeStrict) . Decoder.bytea|] ]+ in fmap concat $ forM settings $ \(t, pti, encoder, decoder) -> [d|