packages feed

hasql-interpolate 0.1.0.4 → 0.2.0.0

raw patch · 3 files changed

+41/−37 lines, 3 filesdep ~timePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: time

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+## 0.2.0.0 -- 2023-08-17++* Relax context of tuple instances for `EncodeRow` from `EncodeValue` to `EncodeField` (https://github.com/awkward-squad/hasql-interpolate/pull/9)+ ## 0.1.0.4 -- 2023-01-10  * Support `mtl-2.3`
hasql-interpolate.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               hasql-interpolate-version:            0.1.0.4+version:            0.2.0.0  author: Travis Staton <hello@travisstaton.com> category: Hasql, Database, PostgreSQL@@ -9,7 +9,7 @@ homepage: https://github.com/awkward-squad/hasql-interpolate license-file: LICENSE license: BSD-3-Clause-tested-with: GHC == 8.10.7, GHC == 9.0.1+tested-with: GHC == 9.2.8, GHC == 9.4.5 maintainer: Travis Staton <hello@travisstaton.com>, Mitchell Rosen synopsis: QuasiQuoter that supports expression interpolation for hasql description:@@ -35,17 +35,17 @@                       Hasql.Interpolate.Internal.EncodeRow                       Hasql.Interpolate.Internal.EncodeRow.TH -    build-depends:    aeson ^>= 1.5 || ^>= 2.0 || ^>= 2.1,+    build-depends:    aeson ^>= 1.5 || ^>= 2.0 || ^>= 2.1 || ^>= 2.2,                       array ^>= 0.5,-                      base ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17,+                      base ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17 || ^>= 4.18,                       bytestring ^>= 0.10 || ^>= 0.11,                       containers ^>= 0.5 || ^>= 0.6,                       haskell-src-meta ^>= 0.8,                       hasql ^>= 1.4 || ^>= 1.5 || ^>= 1.6,-                      megaparsec ^>= 8.0.0 || ^>= 9.0 || ^>= 9.1 || ^>= 9.2 || ^>= 9.3,+                      megaparsec ^>= 8.0.0 || ^>= 9.0 || ^>= 9.1 || ^>= 9.2 || ^>= 9.3 || ^>= 9.4,                       mtl ^>= 2.1 || ^>= 2.2 || ^>= 2.3,                       scientific ^>= 0.3,-                      template-haskell ^>= 2.14 || ^>= 2.15 || ^>= 2.16 || ^>= 2.17 || ^>= 2.18 || ^>= 2.19,+                      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,                       transformers ^>= 0.5 || ^>= 0.6,
lib/Hasql/Interpolate/Internal/EncodeRow/TH.hs view
@@ -10,7 +10,7 @@ import Data.Foldable (foldl') import Data.Functor.Contravariant import qualified Hasql.Encoders as E-import Hasql.Interpolate.Internal.Encoder (EncodeField (..), EncodeValue (..))+import Hasql.Interpolate.Internal.Encoder (EncodeField (..)) import Language.Haskell.TH  -- | Generate a single 'Hasql.Interpolate.EncodeRow' instance for a@@ -22,36 +22,36 @@ genEncodeRowInstance tupSize   | tupSize < 2 = fail "this is just for tuples, must specify a tuple size of 2 or greater"   | otherwise = do-    tyVars <- replicateM tupSize (newName "x")-    context <- traverse (\x -> [t|EncodeValue $(varT x)|]) tyVars-    let unzipWithEncoderName = mkName "unzipWithEncoder"-    instanceHead <- [t|$(conT (mkName "EncodeRow")) $(pure $ foldl' AppT (TupleT tupSize) (map VarT tyVars))|]-    innerContName <- newName "k"-    cons <- [e|(:)|]-    kconsTailNames <- traverse (\_ -> newName "tail") tyVars-    let kconsPats :: [Pat]-        kconsPats =-          [ TupP (map VarP tyVars),-            TildeP (TupP (map VarP kconsTailNames))-          ]-        kconsTupBody :: [Exp]-        kconsTupBody =-          let vars = zipWith phi tyVars kconsTailNames-              phi headName tailName = foldl' AppE cons [VarE headName, VarE tailName]-           in vars-        kcons :: Exp-        kcons = LamE kconsPats (TupE (map Just kconsTupBody))-        knil :: Exp-        knil = TupE . map Just $ replicate tupSize (ListE [])-    kenc :: Exp <- do-      let listEncoder = [e|E.param (E.nonNullable (E.foldableArray encodeField))|]-          plucks = map (pluck tupSize) [0 .. tupSize - 1]-      encExps <- traverse (\getTupElem -> [e|contramap $getTupElem $listEncoder|]) plucks-      foldr (\a b -> [e|$(pure a) <> $(b)|]) [e|mempty|] encExps-    let kExp :: Exp-        kExp = foldl' AppE (VarE innerContName) [kcons, knil, kenc, LitE (IntegerL (fromIntegral tupSize))]-    let instanceBody = FunD unzipWithEncoderName [Clause [VarP innerContName] (NormalB kExp) []]-    pure (InstanceD Nothing context instanceHead [instanceBody])+      tyVars <- replicateM tupSize (newName "x")+      context <- traverse (\x -> [t|EncodeField $(varT x)|]) tyVars+      let unzipWithEncoderName = mkName "unzipWithEncoder"+      instanceHead <- [t|$(conT (mkName "EncodeRow")) $(pure $ foldl' AppT (TupleT tupSize) (map VarT tyVars))|]+      innerContName <- newName "k"+      cons <- [e|(:)|]+      kconsTailNames <- traverse (\_ -> newName "tail") tyVars+      let kconsPats :: [Pat]+          kconsPats =+            [ TupP (map VarP tyVars),+              TildeP (TupP (map VarP kconsTailNames))+            ]+          kconsTupBody :: [Exp]+          kconsTupBody =+            let vars = zipWith phi tyVars kconsTailNames+                phi headName tailName = foldl' AppE cons [VarE headName, VarE tailName]+             in vars+          kcons :: Exp+          kcons = LamE kconsPats (TupE (map Just kconsTupBody))+          knil :: Exp+          knil = TupE . map Just $ replicate tupSize (ListE [])+      kenc :: Exp <- do+        let listEncoder = [e|E.param (E.nonNullable (E.foldableArray encodeField))|]+            plucks = map (pluck tupSize) [0 .. tupSize - 1]+        encExps <- traverse (\getTupElem -> [e|contramap $getTupElem $listEncoder|]) plucks+        foldr (\a b -> [e|$(pure a) <> $(b)|]) [e|mempty|] encExps+      let kExp :: Exp+          kExp = foldl' AppE (VarE innerContName) [kcons, knil, kenc, LitE (IntegerL (fromIntegral tupSize))]+      let instanceBody = FunD unzipWithEncoderName [Clause [VarP innerContName] (NormalB kExp) []]+      pure (InstanceD Nothing context instanceHead [instanceBody])  pluck :: Int -> Int -> Q Exp pluck 1 0 = [e|id|]