hasql-th 0.4 → 0.4.0.1
raw patch · 5 files changed
+49/−9 lines, 5 filesdep +template-haskell-compat-v0208dep ~tuple-thPVP ok
version bump matches the API change (PVP)
Dependencies added: template-haskell-compat-v0208
Dependency ranges changed: tuple-th
API changes (from Hackage documentation)
Files
- hasql-th.cabal +2/−2
- library/Hasql/TH.hs +36/−1
- library/Hasql/TH/Exp.hs +10/−3
- library/Hasql/TH/Syntax/Extraction.hs +0/−2
- test/Main/Gen.hs +1/−1
hasql-th.cabal view
@@ -1,5 +1,5 @@ name: hasql-th-version: 0.4+version: 0.4.0.1 category: Hasql, Database, PostgreSQL, Template Haskell synopsis: Template Haskell utilities for Hasql description:@@ -60,9 +60,9 @@ parser-combinators >=1.1 && <1.3, selective >=0.3 && <0.4, template-haskell >=2.8 && <3,+ template-haskell-compat-v0208 >=0.1.2 && <2, text >=1 && <2, text-builder >=0.6.6.1 && <0.7,- tuple-th >=0.2.5 && <0.3, unordered-containers >=0.2.10 && <0.3, uuid >=1.3 && <2, vector >=0.12 && <0.13
library/Hasql/TH.hs view
@@ -21,8 +21,43 @@ As you can see, it completely eliminates the need to mess with codecs. The quasiquoters directly produce `Statement`, which you can then `dimap` over using its `Profunctor` instance to get to your domain types.+ + == Type mappings+ + === Primitives+ + Following is a list of supported Postgres types and their according types on the Haskell end. - === Nullability+ - @bool@ - `Bool`+ - @int2@ - `Int16`+ - @int4@ - `Int32`+ - @int8@ - `Int64`+ - @float4@ - `Float`+ - @float8@ - `Double`+ - @numeric@ - `Data.Scientific.Scientific`+ - @char@ - `Char`+ - @text@ - `Data.Text.Text`+ - @bytea@ - `Data.ByteString.ByteString`+ - @date@ - `Data.Time.Day`+ - @timestamp@ - `Data.Time.LocalTime`+ - @timestamptz@ - `Data.Time.UTCTime`+ - @time@ - `Data.Time.TimeOfDay`+ - @timetz@ - @(`Data.Time.TimeOfDay`, `Data.Time.TimeZone`)@+ - @interval@ - `Data.Time.DiffTime`+ - @uuid@ - `Data.UUID.UUID`+ - @inet@ - @(`Network.IP.Addr.NetAddr` `Network.IP.Addr.IP`)@+ - @json@ - `Data.Aeson.Value`+ - @jsonb@ - `Data.Aeson.Value`+ + === Arrays++ Array mappings are also supported.+ They are specified according to Postgres syntax: by appending one or more @[]@ to the primitive type,+ depending on how many dimensions the array has.+ On the Haskell end array is mapped to generic `Data.Vector.Generic.Base.Vector`,+ allowing you to choose which particular vector implementation to map to.++ === Nulls As you might have noticed in the example, we introduce one change to the Postgres syntax in the way
library/Hasql/TH/Exp.hs view
@@ -1,7 +1,7 @@ module Hasql.TH.Exp where import Hasql.TH.Prelude hiding (sequence_, string, list)-import Language.Haskell.TH+import Language.Haskell.TH.Syntax import qualified Hasql.TH.Prelude as Prelude import qualified Hasql.TH.Syntax.Extraction as Extraction import qualified Hasql.Encoders as Encoders@@ -11,7 +11,7 @@ import qualified Data.ByteString.Unsafe as ByteString import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Vector.Generic as Vector-import qualified TupleTH+import qualified TemplateHaskell.Compat.V0208 as Compat -- * Helpers@@ -58,7 +58,14 @@ tuple = ConE . tupleDataName splitTupleAt :: Int -> Int -> Exp-splitTupleAt arity position = unsafePerformIO $ runQ $ TupleTH.splitTupleAt arity position+splitTupleAt arity position = let+ nameByIndex index = Name (OccName ('_' : show index)) NameS+ names = enumFromTo 0 (pred arity) & map nameByIndex+ pats = names & map VarP+ pat = TupP pats+ exps = names & map VarE+ body = splitAt position exps & \ (a, b) -> Compat.tupE [Compat.tupE a, Compat.tupE b]+ in LamE [pat] body {-| Given a list of divisible functor expressions,
library/Hasql/TH/Syntax/Extraction.hs view
@@ -66,7 +66,6 @@ "inet" -> Right 'Encoders.inet "json" -> Right 'Encoders.json "jsonb" -> Right 'Encoders.jsonb- "enum" -> Right 'Encoders.enum name -> Left ("No value encoder exists for type: " <> name) decoder :: TypecastTypename -> Either Text Decoder@@ -97,7 +96,6 @@ "inet" -> Right 'Decoders.inet "json" -> Right 'Decoders.json "jsonb" -> Right 'Decoders.jsonb- "enum" -> Right 'Decoders.enum name -> Left ("No value decoder exists for type: " <> name) identText :: Ident -> Either Text Text
test/Main/Gen.hs view
@@ -539,7 +539,7 @@ whenClause = WhenClause <$> small aExpr <*> small aExpr inExpr = choice [- SelectInExpr <$> selectWithParens,+ SelectInExpr <$> NoParensSelectWithParens <$> selectNoParens, ExprListInExpr <$> exprList ]