hasql 1.6.2 → 1.6.3
raw patch · 5 files changed
+44/−1 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Hasql.Encoders: unknownEnum :: (a -> Text) -> Value a
Files
- CHANGELOG.md +4/−0
- hasql.cabal +1/−1
- library/Hasql/Encoders.hs +1/−0
- library/Hasql/Private/Encoders.hs +10/−0
- tasty/Main.hs +28/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 1.6.3++- Added `unknownEnum` encoder+ # 1.6.2 - Added composite encoder
hasql.cabal view
@@ -1,5 +1,5 @@ name: hasql-version: 1.6.2+version: 1.6.3 category: Hasql, Database, PostgreSQL synopsis: An efficient PostgreSQL driver with a flexible mapping API description:
library/Hasql/Encoders.hs view
@@ -43,6 +43,7 @@ name, oid, enum,+ unknownEnum, unknown, array, foldableArray,
library/Hasql/Private/Encoders.hs view
@@ -269,6 +269,16 @@ enum mapping = Value (Value.unsafePTI PTI.text (const (A.text_strict . mapping)) (C.text . mapping)) -- |+-- Variation of 'enum' with unknown OID.+-- This function does not identify the type to Postgres,+-- so Postgres must be able to derive the type from context.+-- When you find yourself in such situation just provide an explicit type in the query+-- using the :: operator.+{-# INLINEABLE unknownEnum #-}+unknownEnum :: (a -> Text) -> Value a+unknownEnum mapping = Value (Value.unsafePTI PTI.binaryUnknown (const (A.text_strict . mapping)) (C.text . mapping))++-- | -- Identifies the value with the PostgreSQL's \"unknown\" type, -- thus leaving it up to Postgres to infer the actual type of the value. --
tasty/Main.hs view
@@ -127,6 +127,34 @@ in do x <- Connection.with (Session.run session) assertEqual (show x) (Right (Right ((1, True), ("hello", 3)))) x,+ testGroup "unknownEnum" $+ [ testCase "" $ do+ res <- DSL.session $ do+ let statement =+ Statement.Statement sql mempty Decoders.noResult True+ where+ sql =+ "drop type if exists mood"+ in DSL.statement () statement+ let statement =+ Statement.Statement sql mempty Decoders.noResult True+ where+ sql =+ "create type mood as enum ('sad', 'ok', 'happy')"+ in DSL.statement () statement+ let statement =+ Statement.Statement sql encoder decoder True+ where+ sql =+ "select $1"+ decoder =+ (Decoders.singleRow ((Decoders.column . Decoders.nonNullable) (Decoders.enum (Just . id))))+ encoder =+ Encoders.param (Encoders.nonNullable (Encoders.unknownEnum id))+ in DSL.statement "ok" statement++ assertEqual "" (Right "ok") res+ ], testCase "Composite encoding" $ do let value = (123, 456, 789, "abc")