packages feed

hasql-interpolate 0.2.1.0 → 0.2.2.0

raw patch · 7 files changed

+66/−15 lines, 7 filesdep ~hasqldep ~timePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: hasql, time

API changes (from Hackage documentation)

+ Hasql.Interpolate: ($dmdecodeRow) :: (DecodeRow a, Generic a, GDecodeRow (Rep a)) => Row a
+ Hasql.Interpolate: ($dmunzipWithEncoder) :: (EncodeRow a, Generic a, GEncodeRow (Rep a)) => (forall x. () => (a -> x -> x) -> x -> Params x -> Int -> r) -> r
+ Hasql.Interpolate: JsonBytes :: ByteString -> JsonBytes
+ Hasql.Interpolate: JsonbBytes :: ByteString -> JsonbBytes
+ Hasql.Interpolate: newtype JsonBytes
+ Hasql.Interpolate: newtype JsonbBytes
- Hasql.Interpolate: decodeRow :: (DecodeRow a, Generic a, GDecodeRow (Rep a)) => Row a
+ Hasql.Interpolate: decodeRow :: DecodeRow a => Row a
- Hasql.Interpolate: unzipWithEncoder :: (EncodeRow a, Generic a, GEncodeRow (Rep a)) => (forall x. (a -> x -> x) -> x -> Params x -> Int -> r) -> r
+ Hasql.Interpolate: unzipWithEncoder :: EncodeRow a => (forall x. () => (a -> x -> x) -> x -> Params x -> Int -> r) -> r

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+## 0.2.2.0 -- 2024-05-07++* Make compile-time syntax error messages prettier+* Add `EncodeValue` instances for `ByteString` and `LazyByteString`+* Add `JsonBytes` and `JsonbBytes` newtypes+ ## 0.2.1.0 -- 2023-08-29  * Fix encoder generation bug (https://github.com/awkward-squad/hasql-interpolate/pull/10)
hasql-interpolate.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               hasql-interpolate-version:            0.2.1.0+version:            0.2.2.0  author: Travis Staton <hello@travisstaton.com> category: Hasql, Database, PostgreSQL@@ -37,17 +37,17 @@      build-depends:    aeson ^>= 1.5 || ^>= 2.0 || ^>= 2.1 || ^>= 2.2,                       array ^>= 0.5,-                      base ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17 || ^>= 4.18,-                      bytestring ^>= 0.10 || ^>= 0.11,-                      containers ^>= 0.5 || ^>= 0.6,+                      base ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17 || ^>= 4.18 || ^>= 4.19,+                      bytestring ^>= 0.10 || ^>= 0.11 || ^>= 0.12,+                      containers ^>= 0.5 || ^>= 0.6 || ^>= 0.7,                       haskell-src-meta ^>= 0.8,-                      hasql ^>= 1.4 || ^>= 1.5 || ^>= 1.6,-                      megaparsec ^>= 8.0.0 || ^>= 9.0 || ^>= 9.1 || ^>= 9.2 || ^>= 9.3 || ^>= 9.4,+                      hasql ^>= 1.4 || ^>= 1.5 || ^>= 1.6 || ^>= 1.7,+                      megaparsec ^>= 8.0.0 || ^>= 9.0 || ^>= 9.1 || ^>= 9.2 || ^>= 9.3 || ^>= 9.4 || ^>= 9.5 || ^>= 9.6,                       mtl ^>= 2.1 || ^>= 2.2 || ^>= 2.3,                       scientific ^>= 0.3,-                      template-haskell ^>= 2.14 || ^>= 2.15 || ^>= 2.16 || ^>= 2.17 || ^>= 2.18 || ^>= 2.19 || ^>= 2.20,-                      text ^>= 1.2.4 || ^>= 2.0,-                      time ^>= 1.9.3 || ^>= 1.10 || ^>= 1.11 || ^>= 1.12,+                      template-haskell ^>= 2.14 || ^>= 2.15 || ^>= 2.16 || ^>= 2.17 || ^>= 2.18 || ^>= 2.19 || ^>= 2.20 || ^>= 2.21,+                      text ^>= 1.2.4 || ^>= 2.0 || ^>= 2.1,+                      time ^>= 1.9.3 || ^>= 1.10 || ^>= 1.11 || ^>= 1.12 || ^>= 1.14,                       transformers ^>= 0.5 || ^>= 0.6,                       uuid ^>= 1.3,                       vector ^>= 0.11 || ^>= 0.12 || ^>= 0.13,
lib/Hasql/Interpolate.hs view
@@ -24,6 +24,8 @@     RowsAffected (..),     Json (..),     Jsonb (..),+    JsonBytes (..),+    JsonbBytes (..),     AsJson (..),     AsJsonb (..),     CompositeValue (..),
lib/Hasql/Interpolate/Internal/Decoder/TH.hs view
@@ -26,6 +26,6 @@         go b _a = do           [e|$(b) <*> column decodeField|] -    instanceBodyExp <- foldl' go [e|$(pure tupSection) <$> column decodeField|] (tail tyVars)+    instanceBodyExp <- foldl' go [e|$(pure tupSection) <$> column decodeField|] (drop 1 tyVars)     let instanceBody = FunD (mkName "decodeRow") [Clause [] (NormalB instanceBodyExp) []]     pure (InstanceD Nothing context instanceHead [instanceBody])
lib/Hasql/Interpolate/Internal/Encoder.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE UndecidableInstances #-}@@ -9,6 +10,10 @@   ) where +import Data.ByteString (ByteString)+import Data.ByteString.Lazy (LazyByteString)+import Data.ByteString.Lazy qualified as ByteString.Lazy+import Data.Functor.Contravariant (contramap) import Data.Int import Data.Scientific (Scientific) import Data.Text (Text)@@ -97,6 +102,14 @@ -- | Encode a 'UUID' as a postgres @uuid@ using 'uuid' instance EncodeValue UUID where   encodeValue = uuid++-- | Encode a 'ByteString' as a postgres @bytea@ using 'bytea'+instance EncodeValue ByteString where+  encodeValue = bytea++-- | Encode a 'LazyByteString' as a postgres @bytea@ using 'bytea'+instance EncodeValue LazyByteString where+  encodeValue = contramap ByteString.Lazy.toStrict bytea  -- | You do not need to define instances for this class; The two -- instances exported here cover all uses. The class only exists to
lib/Hasql/Interpolate/Internal/Json.hs view
@@ -4,6 +4,8 @@ module Hasql.Interpolate.Internal.Json   ( Json (..),     Jsonb (..),+    JsonBytes (..),+    JsonbBytes (..),     AsJson (..),     AsJsonb (..),   )@@ -12,6 +14,7 @@ import Data.Aeson import qualified Data.Aeson as Aeson import Data.Bifunctor (first)+import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as BL import Data.Coerce import Data.Functor.Contravariant@@ -23,23 +26,33 @@  -- | Newtype for 'Hasql.Interpolate.Decoder.DecodeValue' / -- 'Hasql.Interpolate.Encoder.EncodeValue' instances that converts--- between a postgres json type and an Aeson 'Value'+-- between a postgres @jsonb@ and an Aeson 'Value' newtype Jsonb = Jsonb Value  -- | Newtype for 'Hasql.Interpolate.Decoder.DecodeValue' / -- 'Hasql.Interpolate.Encoder.EncodeValue' instances that converts--- between a postgres json type and an Aeson 'Value'+-- between a postgres @json@ and an Aeson 'Value' newtype Json = Json Value  -- | Newtype for 'Hasql.Interpolate.Decoder.DecodeValue' / -- 'Hasql.Interpolate.Encoder.EncodeValue' instances that converts--- between a postgres json type and anything that is an instance of+-- between a postgres @jsonb@ and a 'ByteString'+newtype JsonbBytes = JsonbBytes ByteString++-- | Newtype for 'Hasql.Interpolate.Decoder.DecodeValue' /+-- 'Hasql.Interpolate.Encoder.EncodeValue' instances that converts+-- between a postgres @json@ and a 'ByteString'+newtype JsonBytes = JsonBytes ByteString++-- | Newtype for 'Hasql.Interpolate.Decoder.DecodeValue' /+-- 'Hasql.Interpolate.Encoder.EncodeValue' instances that converts+-- between a postgres @json@ and anything that is an instance of -- 'FromJSON' / 'ToJSON' newtype AsJson a = AsJson a  -- | Newtype for 'Hasql.Interpolate.Decoder.DecodeValue' / -- 'Hasql.Interpolate.Encoder.EncodeValue' instances that converts--- between a postgres jsonb type and anything that is an instance of+-- between a postgres @jsonb@ and anything that is an instance of -- 'FromJSON' / 'ToJSON' newtype AsJsonb a = AsJsonb a @@ -51,6 +64,14 @@ instance DecodeValue Json where   decodeValue = coerce D.json +-- | Parse a postgres @jsonb@ using 'D.jsonbBytes'+instance DecodeValue JsonbBytes where+  decodeValue = coerce (D.jsonbBytes Right)++-- | Parse a postgres @json@ using 'D.jsonBytes'+instance DecodeValue JsonBytes where+  decodeValue = coerce (D.jsonBytes Right)+ -- | Parse a postgres @json@ to anything that is an instance of -- 'Aeson.FromJSON' instance Aeson.FromJSON a => DecodeValue (AsJson a) where@@ -68,6 +89,14 @@ -- | Encode an Aeson 'Aeson.Value' to a postgres @jsonb@ using 'E.jsonb' instance EncodeValue Jsonb where   encodeValue = coerce E.jsonb++-- | Encode a 'ByteString' to a postgres @json@ using 'E.jsonBytes'+instance EncodeValue JsonBytes where+  encodeValue = coerce E.jsonbBytes++-- | Encode a 'ByteString' to a postgres @jsonb@ using 'E.jsonbBytes'+instance EncodeValue JsonbBytes where+  encodeValue = coerce E.jsonbBytes  -- | Encode anything that is an instance of 'Aeson.ToJSON' to a postgres @json@ instance Aeson.ToJSON a => EncodeValue (AsJson a) where
lib/Hasql/Interpolate/Internal/TH.hs view
@@ -43,6 +43,7 @@     anySingle,     chunk,     eof,+    errorBundlePretty,     notFollowedBy,     runParser,     single,@@ -291,7 +292,7 @@   QuasiQuoter     { quoteExp = \str -> do         case parseSqlExpr str of-          Left err -> fail (show err)+          Left err -> fail (errorBundlePretty err)           Right sqlExpr -> compileSqlExpr sqlExpr,       quotePat = undefined,       quoteType = undefined,