Add lazy variations of bytestring json encoders

Addresses #149.
This commit is contained in:
Nikita Volkov 2022-09-07 21:53:39 +03:00
parent 67e2034f08
commit 3220655db9
4 changed files with 23 additions and 4 deletions

View File

@ -1,3 +1,7 @@
# 1.6.1
- Added `jsonLazyBytes` and `jsonbLazyBytes`
# 1.6
- Added position to `ServerError` (breaking change).

View File

@ -1,5 +1,5 @@
name: hasql
version: 1.6.0.1
version: 1.6.1
category: Hasql, Database, PostgreSQL
synopsis: An efficient PostgreSQL driver with a flexible mapping API
description:
@ -64,13 +64,13 @@ library
contravariant >=1.3 && <2,
dlist ==0.8.* || >=1 && <2,
hashable >=1.2 && <2,
hashtables >=1.1 && <2,
hashtables >=1.3 && <2,
mtl >=2 && <3,
postgresql-binary >=0.12.4 && <0.13,
postgresql-binary >=0.12.5 && <0.13,
postgresql-libpq ==0.9.*,
profunctors >=5.1 && <6,
text >=1 && <3,
text-builder >=0.6.1.2 && <0.7,
text-builder >=0.6.7 && <0.7,
transformers >=0.3 && <0.7,
vector >=0.10 && <0.14

View File

@ -36,8 +36,10 @@ module Hasql.Encoders
inet,
json,
jsonBytes,
jsonLazyBytes,
jsonb,
jsonbBytes,
jsonbLazyBytes,
enum,
unknown,
array,

View File

@ -2,6 +2,7 @@
-- A DSL for declaration of query parameter encoders.
module Hasql.Private.Encoders where
import qualified Data.ByteString.Lazy as LazyByteString
import qualified Hasql.Private.Encoders.Array as Array
import qualified Hasql.Private.Encoders.Params as Params
import qualified Hasql.Private.Encoders.Value as Value
@ -228,6 +229,12 @@ json = Value (Value.unsafePTIWithShow PTI.json (const A.json_ast))
jsonBytes :: Value ByteString
jsonBytes = Value (Value.unsafePTIWithShow PTI.json (const A.json_bytes))
-- |
-- Encoder of @JSON@ values from raw JSON as lazy ByteString.
{-# INLINEABLE jsonLazyBytes #-}
jsonLazyBytes :: Value ByteString
jsonLazyBytes = Value (Value.unsafePTIWithShow PTI.json (const A.json_bytes_lazy))
-- |
-- Encoder of @JSONB@ values from JSON AST.
{-# INLINEABLE jsonb #-}
@ -240,6 +247,12 @@ jsonb = Value (Value.unsafePTIWithShow PTI.jsonb (const A.jsonb_ast))
jsonbBytes :: Value ByteString
jsonbBytes = Value (Value.unsafePTIWithShow PTI.jsonb (const A.jsonb_bytes))
-- |
-- Encoder of @JSONB@ values from raw JSON as lazy ByteString.
{-# INLINEABLE jsonbLazyBytes #-}
jsonbLazyBytes :: Value ByteString
jsonbLazyBytes = Value (Value.unsafePTIWithShow PTI.jsonb (const A.jsonb_bytes_lazy))
-- |
-- Given a function,
-- which maps a value into a textual enum label used on the DB side,