Raw JSON support

This commit is contained in:
Nikita Volkov 2016-02-09 13:14:19 +03:00
parent 5ec981f552
commit ff3dd818df
3 changed files with 44 additions and 10 deletions

View File

@ -1,7 +1,7 @@
name:
hasql
version:
0.19.6
0.19.7
category:
Hasql, Database, PostgreSQL
synopsis:
@ -74,7 +74,7 @@ library
-- parsing:
attoparsec >= 0.10 && < 0.14,
-- database:
postgresql-binary >= 0.7.7 && < 0.8,
postgresql-binary >= 0.8 && < 0.9,
postgresql-libpq == 0.9.*,
-- data:
dlist >= 0.7 && < 0.8,

View File

@ -38,7 +38,9 @@ module Hasql.Decoders
interval,
uuid,
json,
jsonBytes,
jsonb,
jsonbBytes,
array,
composite,
hstore,
@ -414,20 +416,36 @@ uuid =
Value (Value.decoder (const Decoder.uuid))
-- |
-- Decoder of the @JSON@ values.
-- Decoder of the @JSON@ values into a JSON AST.
--
{-# INLINABLE json #-}
json :: Value Aeson.Value
json =
Value (Value.decoder (const Decoder.json))
Value (Value.decoder (const Decoder.json_ast))
-- |
-- Decoder of the @JSONB@ values.
-- Decoder of the @JSON@ values into a raw JSON 'ByteString'.
--
{-# INLINABLE jsonBytes #-}
jsonBytes :: (ByteString -> Either Text a) -> Value a
jsonBytes fn =
Value (Value.decoder (const (Decoder.json_bytes fn)))
-- |
-- Decoder of the @JSONB@ values into a JSON AST.
--
{-# INLINABLE jsonb #-}
jsonb :: Value Aeson.Value
jsonb =
Value (Value.decoder (const Decoder.jsonb))
Value (Value.decoder (const Decoder.jsonb_ast))
-- |
-- Decoder of the @JSONB@ values into a raw JSON 'ByteString'.
--
{-# INLINABLE jsonbBytes #-}
jsonbBytes :: (ByteString -> Either Text a) -> Value a
jsonbBytes fn =
Value (Value.decoder (const (Decoder.jsonb_bytes fn)))
-- |
-- Lifts a custom value decoder function to a 'Value' decoder.

View File

@ -27,7 +27,9 @@ module Hasql.Encoders
interval,
uuid,
json,
jsonBytes,
jsonb,
jsonbBytes,
array,
enum,
unknown,
@ -300,18 +302,32 @@ uuid =
Value (Value.unsafePTI PTI.uuid (const Encoder.uuid))
-- |
-- Encoder of @JSON@ values.
-- Encoder of @JSON@ values from JSON AST.
{-# INLINABLE json #-}
json :: Value Aeson.Value
json =
Value (Value.unsafePTI PTI.json (const Encoder.json))
Value (Value.unsafePTI PTI.json (const Encoder.json_ast))
-- |
-- Encoder of @JSONB@ values.
-- Encoder of @JSON@ values from raw JSON.
{-# INLINABLE jsonBytes #-}
jsonBytes :: Value ByteString
jsonBytes =
Value (Value.unsafePTI PTI.json (const Encoder.json_bytes))
-- |
-- Encoder of @JSONB@ values from JSON AST.
{-# INLINABLE jsonb #-}
jsonb :: Value Aeson.Value
jsonb =
Value (Value.unsafePTI PTI.jsonb (const Encoder.jsonb))
Value (Value.unsafePTI PTI.jsonb (const Encoder.jsonb_ast))
-- |
-- Encoder of @JSONB@ values from raw JSON.
{-# INLINABLE jsonbBytes #-}
jsonbBytes :: Value ByteString
jsonbBytes =
Value (Value.unsafePTI PTI.jsonb (const Encoder.jsonb_bytes))
-- |
-- Unlifts the 'Array' encoder to the plain 'Value' encoder.