Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/Hasql/Encoders.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module Hasql.Encoders
jsonbBytes,
enum,
unknown,
unknownLazy,
unknown',
array,
foldableArray,
-- * Array
Expand Down
12 changes: 10 additions & 2 deletions library/Hasql/Private/Encoders.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import qualified Hasql.Private.Encoders.Value as Value
import qualified Hasql.Private.Encoders.Array as Array
import qualified Hasql.Private.PTI as PTI
import qualified Hasql.Private.Prelude as Prelude

import qualified Data.ByteString.Lazy as LBS

-- * Parameters Product Encoder
-------------------------
Expand Down Expand Up @@ -280,6 +280,10 @@ produces an encoder of that value.
enum :: (a -> Text) -> Value a
enum mapping = Value (Value.unsafePTI PTI.text (const (A.text_strict . mapping)) (C.text . mapping))

{-# INLINABLE unknown' #-}
unknown' :: Show a => (a -> A.Encoding) -> Value a
unknown' enc = Value (Value.unsafePTIWithShow PTI.unknown (const enc))

{-|
Identifies the value with the PostgreSQL's \"unknown\" type,
thus leaving it up to Postgres to infer the actual type of the value.
Expand All @@ -291,7 +295,11 @@ section of the Postgres' documentation.
-}
{-# INLINABLE unknown #-}
unknown :: Value ByteString
unknown = Value (Value.unsafePTIWithShow PTI.unknown (const A.bytea_strict))
unknown = unknown' A.bytea_strict

{-# INLINABLE unknownLazy #-}
unknownLazy :: Value LBS.ByteString
unknownLazy = unknown' A.bytea_lazy

{-|
Lift an array encoder into a parameter encoder.
Expand Down