hasql 1.6.1.4 → 1.6.2
raw patch · 6 files changed
+52/−4 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Hasql.Encoders: name :: Value Text
+ Hasql.Encoders: oid :: Value Int32
Files
- CHANGELOG.md +5/−0
- hasql.cabal +1/−1
- library/Hasql/Encoders.hs +2/−0
- library/Hasql/Private/Encoders.hs +14/−2
- library/Hasql/Private/PTI.hs +3/−1
- tasty/Main.hs +27/−0
CHANGELOG.md view
@@ -1,3 +1,8 @@+# 1.6.2++- Added composite encoder+- Added `oid` and `name` encoders+ # 1.6.1 - Added `jsonLazyBytes` and `jsonbLazyBytes`
hasql.cabal view
@@ -1,5 +1,5 @@ name: hasql-version: 1.6.1.4+version: 1.6.2 category: Hasql, Database, PostgreSQL synopsis: An efficient PostgreSQL driver with a flexible mapping API description:
library/Hasql/Encoders.hs view
@@ -40,6 +40,8 @@ jsonb, jsonbBytes, jsonbLazyBytes,+ name,+ oid, enum, unknown, array,
library/Hasql/Private/Encoders.hs view
@@ -249,6 +249,18 @@ jsonbLazyBytes = Value (Value.unsafePTIWithShow PTI.jsonb (const A.jsonb_bytes_lazy)) -- |+-- Encoder of @OID@ values.+{-# INLINEABLE oid #-}+oid :: Value Int32+oid = Value (Value.unsafePTIWithShow PTI.oid (const A.int4_int32))++-- |+-- Encoder of @NAME@ values.+{-# INLINEABLE name #-}+name :: Value Text+name = Value (Value.unsafePTIWithShow PTI.name (const A.text_strict))++-- | -- Given a function, -- which maps a value into a textual enum label used on the DB side, -- produces an encoder of that value.@@ -269,7 +281,7 @@ -- it is the only encoder that doesn't use the binary format. {-# INLINEABLE unknown #-} unknown :: Value ByteString-unknown = Value (Value.unsafePTIWithShow PTI.unknown (const A.bytea_strict))+unknown = Value (Value.unsafePTIWithShow PTI.textUnknown (const A.bytea_strict)) -- | -- Lift an array encoder into a value encoder.@@ -282,7 +294,7 @@ -- Lift a composite encoder into a value encoder. composite :: Composite a -> Value a composite (Composite encode print) =- Value (Value.unsafePTI PTI.unknown encodeValue printValue)+ Value (Value.unsafePTI PTI.binaryUnknown encodeValue printValue) where encodeValue idt val = A.composite $ encode val idt
library/Hasql/Private/PTI.hs view
@@ -143,7 +143,9 @@ txid_snapshot = mkPTI LibPQ.Binary 2970 (Just 2949) -unknown = mkPTI LibPQ.Text 705 (Just 705)+textUnknown = mkPTI LibPQ.Text 705 (Just 705)++binaryUnknown = mkPTI LibPQ.Binary 705 (Just 705) uuid = mkPTI LibPQ.Binary 2950 (Just 2951)
tasty/Main.hs view
@@ -127,6 +127,33 @@ in do x <- Connection.with (Session.run session) assertEqual (show x) (Right (Right ((1, True), ("hello", 3)))) x,+ testCase "Composite encoding" $ do+ let value =+ (123, 456, 789, "abc")+ res <-+ let statement =+ Statement.Statement sql encoder decoder True+ where+ sql =+ "select $1 :: pg_enum"+ encoder =+ Encoders.param . Encoders.nonNullable . Encoders.composite . mconcat $+ [ contramap (\(a, _, _, _) -> a) . Encoders.field . Encoders.nonNullable $ Encoders.oid,+ contramap (\(_, a, _, _) -> a) . Encoders.field . Encoders.nonNullable $ Encoders.oid,+ contramap (\(_, _, a, _) -> a) . Encoders.field . Encoders.nonNullable $ Encoders.float4,+ contramap (\(_, _, _, a) -> a) . Encoders.field . Encoders.nonNullable $ Encoders.name+ ]+ decoder =+ Decoders.singleRow $+ (Decoders.column . Decoders.nonNullable . Decoders.composite)+ ( (,,,)+ <$> (Decoders.field . Decoders.nonNullable) Decoders.int4+ <*> (Decoders.field . Decoders.nonNullable) Decoders.int4+ <*> (Decoders.field . Decoders.nonNullable) Decoders.float4+ <*> (Decoders.field . Decoders.nonNullable) Decoders.text+ )+ in Connection.with $ Session.run $ Session.statement value statement+ assertEqual "" (Right (Right value)) res, testCase "Empty array" $ let io = do