packages feed

hasql-postgres 0.9.0 → 0.9.1

raw patch · 5 files changed

+82/−13 lines, 5 filesdep ~postgresql-binarysetup-changedPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: postgresql-binary

API changes (from Hackage documentation)

+ Hasql.Postgres: Unknown :: ByteString -> Unknown
+ Hasql.Postgres: instance Mapping Postgres Unknown
+ Hasql.Postgres: newtype Unknown

Files

CHANGELOG.md view
@@ -1,3 +1,6 @@+# 0.9.1+* The Unknown type got implemented+ # 0.9.0 * The unit result handler no longer fails on statements, which do produce results * The dependency on "list-t" got relaxed
Setup.hs view
@@ -18,17 +18,7 @@   { buildHook = \pkg lbi hooks flags -> do      generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi      buildHook simpleUserHooks pkg lbi hooks flags-  , postHaddock = \args flags pkg lbi -> do-     copyFiles normal (haddockOutputDir flags pkg) [("images","Hierarchy.png")]-     postHaddock simpleUserHooks args flags pkg lbi   }--haddockOutputDir :: Package p => HaddockFlags -> p -> FilePath-haddockOutputDir flags pkg = destDir where-  baseDir = case haddockDistPref flags of-    NoFlag -> "."-    Flag x -> x-  destDir = baseDir </> "doc" </> "html" </> display (packageName pkg)  generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO () generateBuildModule verbosity pkg lbi = do
hasql-postgres.cabal view
@@ -1,7 +1,7 @@ name:   hasql-postgres version:-  0.9.0+  0.9.1 synopsis:   A "PostgreSQL" backend for the "hasql" library description:@@ -139,6 +139,8 @@   default-language:     Haskell2010   build-depends:+    -- database:+    postgresql-binary,     hasql-postgres,     hasql-backend,     hasql >= 0.4 && < 0.6,
hspec/Main.hs view
@@ -11,9 +11,7 @@ import qualified Data.Text import qualified Data.Text.Lazy import qualified Data.ByteString-import qualified Data.ByteString.Char8 import qualified Data.ByteString.Lazy-import qualified Data.ByteString.Lazy.Char8 import qualified ListT import qualified SlaveThread import qualified Control.Concurrent.SSem as SSem@@ -22,6 +20,7 @@ import qualified Hasql.Postgres as HP import qualified Data.Scientific as Scientific import qualified Data.Vector as Vector+import qualified PostgreSQLBinary.Encoder as PBE   type Text = Data.Text.Text@@ -117,6 +116,54 @@      describe "Mapping of" $ do +      describe "Enum" $ do++        it "casts text" $ do+          session1 $ do+            H.tx Nothing $ do+              H.unit [H.q| DROP TYPE IF EXISTS mood |]+              H.unit [H.q| CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy') |]+            liftIO . (flip shouldBe) (Just (Identity ("ok" :: Text))) =<< do +              H.tx Nothing $ H.single $ [H.q|SELECT (? :: mood)|] ("ok" :: Text)++      describe "Unknown" $ do++        it "encodes to enum" $ do+          session1 $ do+            H.tx Nothing $ do+              H.unit [H.q| DROP TABLE IF EXISTS a |]+              H.unit [H.q| DROP TYPE IF EXISTS mood |]+              H.unit [H.q| CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy') |]+              H.unit [H.q| CREATE TABLE a (id SERIAL NOT NULL, +                                           mood mood NOT NULL,+                                           PRIMARY KEY (id)) |]+              H.unit $ [H.q| INSERT INTO a (mood) VALUES (?) |] (HP.Unknown "ok")+              H.unit $ [H.q| INSERT INTO a (mood) VALUES (?) |] (HP.Unknown "ok")+              H.unit $ [H.q| INSERT INTO a (mood) VALUES (?) |] (HP.Unknown "happy")+            liftIO . (flip shouldBe) ([1, 2] :: [Int]) . fmap runIdentity =<< do +              H.tx Nothing $ H.list $ [H.q|SELECT id FROM a WHERE mood = ?|] (HP.Unknown "ok")++        it "encodes Int64 into \"int8\" using a \"postgresql-binary\" encoder" $ do+          session1 $ tx Nothing $ unit $+            [q| SELECT (? :: int8) |] +              (HP.Unknown . PBE.int8 . Left $ 12345)++        it "does not encode Int64 into \"int4\" using a \"postgresql-binary\" encoder" $ do+          (flip shouldThrow) (\case H.ErroneousResult _ -> True; _ -> False) $+            session1 $ tx Nothing $ unit $+              [q| SELECT (? :: int4)|] +                (HP.Unknown . PBE.int8 . Left $ 12345)++        it "encodes Int64 into \"int8\" using a \"postgresql-binary\" encoder" $ do+          session1 $ tx Nothing $ unit $+            [q| SELECT (? :: int8) |] +              (HP.Unknown . PBE.int8 . Left $ 12345)++        it "encodes Day into \"date\" using a \"postgresql-binary\" encoder" $ do+          session1 $ tx Nothing $ unit $+            [q| SELECT (? :: date) |] +              (HP.Unknown . PBE.date $ (read "1900-01-01" :: Day))+                     describe "Maybe" $ do         it "" $ do           session1 $ do
library/Hasql/Postgres.hs view
@@ -15,6 +15,7 @@ (   Postgres(..),   Connector.Settings(..),+  Unknown(..) ) where @@ -386,4 +387,30 @@ instance Backend.Mapping Postgres UUID where   renderValue = renderValueUsingMapping   parseResult = parseResultUsingMapping+++-- ** Custom types+-------------------------++-- |+-- A wrapper around a 'ByteString',+-- which identifies the value with the PostgreSQL's \"unknown\" type,+-- thus leaving the choice of the type to Postgres.+-- The bytestring needs to be encoded according to the Postgres binary format+-- of the type it expects.+-- +-- Essentially this is a low-level hook into the phases of encoding and decoding+-- of values with custom codecs.+-- <http://hackage.haskell.org/package/postgresql-binary The "postgresql-binary" library> +-- is your toolchain when dealing with this type.+newtype Unknown = +  Unknown ByteString++-- |+-- Maps to @unknown@.+instance Backend.Mapping Postgres Unknown where+  renderValue (Unknown x) = +    StatementArgument (PTI.oidPQ (PTI.ptiOID (PTI.unknown))) (const $ Just x)+  parseResult (Result _ x) = +    maybe (Left "Decoding a NULL to Unknown") (Right . Unknown) x