hasql 1.6.1.3 → 1.6.1.4
raw patch · 8 files changed
+77/−40 lines, 8 filesdep ~hashtablesdep ~postgresql-binaryPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependency ranges changed: hashtables, postgresql-binary
API changes (from Hackage documentation)
+ Hasql.Encoders: composite :: Composite a -> Value a
+ Hasql.Encoders: data Composite a
+ Hasql.Encoders: field :: NullableOrNot Value a -> Composite a
Files
- README.md +9/−4
- benchmarks/Main.hs +0/−4
- hasql.cabal +3/−3
- library/Hasql/Encoders.hs +5/−0
- library/Hasql/Private/Decoders.hs +0/−16
- library/Hasql/Private/Decoders/Row.hs +0/−2
- library/Hasql/Private/Encoders.hs +60/−9
- library/Hasql/Private/PTI.hs +0/−2
README.md view
@@ -1,12 +1,17 @@-# What Hasql is+# Summary +Hasql is a highly efficient PostgreSQL driver for Haskell with a typesafe yet flexible mapping API. It targets both the users, who need maximum control, and the users who face the typical tasks of DB-powered applications, providing them with higher-level APIs. Currently it is known to be [the fastest driver](https://nikita-volkov.github.io/hasql-benchmarks/) in the Haskell ecosystem.++Hasql also is one of the supported targets of the [pGenie](https://pgenie.io) code generator, which empowers it with schema and query validation, and relieves you from boilerplate.++# Status+ [](https://travis-ci.org/nikita-volkov/hasql) [](https://hackage.haskell.org/package/hasql) -Hasql is a highly efficient PostgreSQL driver and a mapping API. It targets both the users, who need a low level of abstraction, and the users, who face the typical tasks of DB-powered applications, providing them with higher-level APIs.-+Hasql is production-ready, actively maintained and the API is pretty stable. It's used by many companies and most notably by the [Postgrest](https://postgrest.org/) project. -## Ecosystem+# Ecosystem Hasql is not just a single library, it is a granular ecosystem of composable libraries, each isolated to perform its own task and stay simple.
benchmarks/Main.hs view
@@ -31,8 +31,6 @@ -- * Sessions --------------------------- sessionWithManySmallParameters :: Vector (Int64, Int64) -> B.Session () sessionWithManySmallParameters = error "TODO: sessionWithManySmallParameters"@@ -54,8 +52,6 @@ replicateM 1000 (B.statement () statementWithSingleRow) -- * Statements--------------------------- statementWithManyParameters :: C.Statement (Vector (Int64, Int64)) () statementWithManyParameters =
hasql.cabal view
@@ -1,5 +1,5 @@ name: hasql-version: 1.6.1.3+version: 1.6.1.4 category: Hasql, Database, PostgreSQL synopsis: An efficient PostgreSQL driver with a flexible mapping API description:@@ -65,10 +65,10 @@ contravariant >=1.3 && <2, dlist ==0.8.* || >=1 && <2, hashable >=1.2 && <2,- hashtables >=1.3 && <2,+ hashtables >=1.1 && <2, mtl >=2 && <3, network-ip >=0.3.0.3 && <0.4,- postgresql-binary >=0.13 && <0.14,+ postgresql-binary >=0.13.1 && <0.14, postgresql-libpq ==0.9.*, profunctors >=5.1 && <6, scientific >=0.3 && <0.4,
library/Hasql/Encoders.hs view
@@ -44,11 +44,16 @@ unknown, array, foldableArray,+ composite, -- * Array Array, element, dimension,++ -- * Composite+ Composite,+ field, ) where
library/Hasql/Private/Decoders.hs view
@@ -19,8 +19,6 @@ -- * Result --------------------------- -- | -- Decoder of a query result. newtype Result a = Result (Results.Results a) deriving (Functor)@@ -52,8 +50,6 @@ -- ** Multi-row traversers --------------------------- -- | -- Foldl multiple rows. {-# INLINEABLE foldlRows #-}@@ -68,8 +64,6 @@ -- ** Specialized multi-row results --------------------------- -- | -- Maybe one row or none. {-# INLINEABLE rowMaybe #-}@@ -93,8 +87,6 @@ -- * Row --------------------------- -- | -- Decoder of an individual row, -- which gets composed of column value decoders.@@ -118,8 +110,6 @@ -- * Nullability --------------------------- -- | -- Extensional specification of nullability over a generic decoder. data NullableOrNot decoder a where@@ -138,8 +128,6 @@ -- * Value --------------------------- -- | -- Decoder of a value. newtype Value a = Value (Value.Value a)@@ -371,8 +359,6 @@ -- * Array decoders --------------------------- -- | -- A generic array decoder. --@@ -409,8 +395,6 @@ Nullable (Value imp) -> Array (Array.value (Value.run imp)) -- * Composite decoders--------------------------- -- | -- Composable decoder of composite values (rows, records).
library/Hasql/Private/Decoders/Row.hs view
@@ -18,8 +18,6 @@ -- * Functions --------------------------- {-# INLINE run #-} run :: Row a -> (LibPQ.Result, LibPQ.Row, LibPQ.Column, Bool) -> IO (Either (Int, RowError) a) run (Row impl) (result, row, columnsAmount, integerDatetimes) =
library/Hasql/Private/Encoders.hs view
@@ -16,8 +16,6 @@ -- * Parameters Product Encoder --------------------------- -- | -- Encoder of some representation of a parameters product. --@@ -80,8 +78,6 @@ -- * Nullability --------------------------- -- | -- Extensional specification of nullability over a generic encoder. data NullableOrNot encoder a where@@ -100,8 +96,6 @@ -- * Value --------------------------- -- | -- Value encoder. newtype Value a = Value (Value.Value a)@@ -278,13 +272,24 @@ unknown = Value (Value.unsafePTIWithShow PTI.unknown (const A.bytea_strict)) -- |--- Lift an array encoder into a parameter encoder.+-- Lift an array encoder into a value encoder. array :: Array a -> Value a array (Array (Array.Array valueOID arrayOID arrayEncoder renderer)) = let encoder env input = A.array (PTI.oidWord32 valueOID) (arrayEncoder env input) in Value (Value.Value arrayOID arrayOID encoder renderer) -- |+-- Lift a composite encoder into a value encoder.+composite :: Composite a -> Value a+composite (Composite encode print) =+ Value (Value.unsafePTI PTI.unknown encodeValue printValue)+ where+ encodeValue idt val =+ A.composite $ encode val idt+ printValue val =+ "ROW (" <> C.intercalate ", " (print val) <> ")"++-- | -- Lift a value encoder of element into a unidimensional array encoder of a foldable value. -- -- This function is merely a shortcut to the following expression:@@ -308,8 +313,6 @@ -- * Array --------------------------- -- | -- Generic array encoder. --@@ -348,3 +351,51 @@ {-# INLINEABLE dimension #-} dimension :: (forall a. (a -> b -> a) -> a -> c -> a) -> Array b -> Array c dimension foldl (Array imp) = Array (Array.dimension foldl imp)++-- * Composite++-- |+-- Composite or row-types encoder.+data Composite a+ = Composite+ (a -> Bool -> A.Composite)+ (a -> [C.Builder])++instance Contravariant Composite where+ contramap f (Composite encode print) =+ Composite (encode . f) (print . f)++instance Divisible Composite where+ divide f (Composite encodeL printL) (Composite encodeR printR) =+ Composite+ (\val idt -> case f val of (lVal, rVal) -> encodeL lVal idt <> encodeR rVal idt)+ (\val -> case f val of (lVal, rVal) -> printL lVal <> printR rVal)+ conquer = mempty++instance Semigroup (Composite a) where+ Composite encodeL printL <> Composite encodeR printR =+ Composite+ (\val idt -> encodeL val idt <> encodeR val idt)+ (\val -> printL val <> printR val)++instance Monoid (Composite a) where+ mempty = Composite mempty mempty++-- | Single field of a row-type.+field :: NullableOrNot Value a -> Composite a+field = \case+ NonNullable (Value (Value.Value elementOID arrayOID encode print)) ->+ Composite+ (\val idt -> A.field (PTI.oidWord32 elementOID) (encode idt val))+ (\val -> [print val])+ Nullable (Value (Value.Value elementOID arrayOID encode print)) ->+ Composite+ ( \val idt -> case val of+ Nothing -> A.nullField (PTI.oidWord32 elementOID)+ Just val -> A.field (PTI.oidWord32 elementOID) (encode idt val)+ )+ ( \val ->+ case val of+ Nothing -> ["NULL"]+ Just val -> [print val]+ )
library/Hasql/Private/PTI.hs view
@@ -19,8 +19,6 @@ -- * Constants --------------------------- abstime = mkPTI LibPQ.Binary 702 (Just 1023) aclitem = mkPTI LibPQ.Binary 1033 (Just 1034)