@@ -201,6 +201,7 @@ module Squeal.PostgreSQL.Binary
202import BinaryParser
202import BinaryParser
203import ByteString.StrictBuilder
203import ByteString.StrictBuilder
204+import Control.Arrow (left)
204import Control.Monad
205import Control.Monad
205import Data.Aeson hiding (Null)
206import Data.Aeson hiding (Null)
206import Data.Int
207import Data.Int
@@ -216,10 +217,12 @@ import Generics.SOP.Record
216import GHC.TypeLits
217import GHC.TypeLits
217import Network.IP.Addr
218import Network.IP.Addr
219−import qualified Data.ByteString.Lazy as Lazy
220+import qualified Data.ByteString.Lazy as Lazy (ByteString)
220−import qualified Data.ByteString as Strict hiding (pack, unpack)
221+import qualified Data.ByteString.Lazy as Lazy.ByteString
222+import qualified Data.ByteString as Strict (ByteString)
221−import qualified Data.Text.Lazy as Lazy
223+import qualified Data.Text.Lazy as Lazy (Text)
222−import qualified Data.Text as Strict hiding (empty)
224+import qualified Data.Text as Strict (Text)
225+import qualified Data.Text as Strict.Text
223import qualified Data.Vector as Vector
226import qualified Data.Vector as Vector
224import qualified GHC.Generics as GHC
227import qualified GHC.Generics as GHC
225import qualified PostgreSQL.Binary.Decoding as Decoding
228import qualified PostgreSQL.Binary.Decoding as Decoding
@@ -262,7 +265,7 @@ instance ToParam Char ('PGchar 1) where toParam = K . Encoding.char_utf8
262instance ToParam Strict.Text 'PGtext where toParam = K . Encoding.text_strict
265instance ToParam Strict.Text 'PGtext where toParam = K . Encoding.text_strict
263instance ToParam Lazy.Text 'PGtext where toParam = K . Encoding.text_lazy
266instance ToParam Lazy.Text 'PGtext where toParam = K . Encoding.text_lazy
264instance ToParam String 'PGtext where
267instance ToParam String 'PGtext where
265− toParam = K . Encoding.text_strict . Strict.pack
268+ toParam = K . Encoding.text_strict . Strict.Text.pack
266instance ToParam Strict.ByteString 'PGbytea where
269instance ToParam Strict.ByteString 'PGbytea where
267 toParam = K . Encoding.bytea_strict
270 toParam = K . Encoding.bytea_strict
268instance ToParam Lazy.ByteString 'PGbytea where
271instance ToParam Lazy.ByteString 'PGbytea where
@@ -278,7 +281,9 @@ instance ToParam UTCTime 'PGtimestamptz where
278instance ToParam DiffTime 'PGinterval where toParam = K . Encoding.interval_int
281instance ToParam DiffTime 'PGinterval where toParam = K . Encoding.interval_int
279instance ToParam Value 'PGjson where toParam = K . Encoding.json_ast
282instance ToParam Value 'PGjson where toParam = K . Encoding.json_ast
280instance ToParam Value 'PGjsonb where toParam = K . Encoding.jsonb_ast
283instance ToParam Value 'PGjsonb where toParam = K . Encoding.jsonb_ast
281−instance ToParam Jsonb 'PGjsonb where toParam = toParam . getJsonb
284+instance ToJSON x => ToParam (Jsonb x) 'PGjsonb where
285+ toParam = K . Encoding.jsonb_bytes
286+ . Lazy.ByteString.toStrict . encode . getJsonb
282instance ToArray x ('NotNull ('PGvararray ty))
287instance ToArray x ('NotNull ('PGvararray ty))
283 => ToParam x ('PGvararray ty) where
288 => ToParam x ('PGvararray ty) where
@@ -306,7 +311,7 @@ instance
306 gshowConstructor constructors (SOP xs)
311 gshowConstructor constructors (SOP xs)
308 K . Encoding.text_strict
313 K . Encoding.text_strict
309− . Strict.pack
314+ . Strict.Text.pack
310 . gshowConstructor (constructorInfo (datatypeInfo (Proxy @x)))
315 . gshowConstructor (constructorInfo (datatypeInfo (Proxy @x)))
312instance ToParam x pg => ToParam (Composite x) pg where
317instance ToParam x pg => ToParam (Composite x) pg where
@@ -440,7 +445,7 @@ instance FromValue ('PGchar 1) Char where fromValue = Decoding.char
440instance FromValue 'PGtext Strict.Text where fromValue = Decoding.text_strict
445instance FromValue 'PGtext Strict.Text where fromValue = Decoding.text_strict
441instance FromValue 'PGtext Lazy.Text where fromValue = Decoding.text_lazy
446instance FromValue 'PGtext Lazy.Text where fromValue = Decoding.text_lazy
442instance FromValue 'PGtext String where
447instance FromValue 'PGtext String where
443− fromValue = Strict.unpack <$> Decoding.text_strict
448+ fromValue = Strict.Text.unpack <$> Decoding.text_strict
444instance FromValue 'PGbytea Strict.ByteString where
449instance FromValue 'PGbytea Strict.ByteString where
445 fromValue = Decoding.bytea_strict
450 fromValue = Decoding.bytea_strict
446instance FromValue 'PGbytea Lazy.ByteString where
451instance FromValue 'PGbytea Lazy.ByteString where
@@ -457,8 +462,12 @@ instance FromValue 'PGinterval DiffTime where
457 fromValue = Decoding.interval_int
462 fromValue = Decoding.interval_int
458instance FromValue 'PGjson Value where fromValue = Decoding.json_ast
463instance FromValue 'PGjson Value where fromValue = Decoding.json_ast
459instance FromValue 'PGjsonb Value where fromValue = Decoding.jsonb_ast
464instance FromValue 'PGjsonb Value where fromValue = Decoding.jsonb_ast
465+instance FromJSON x => FromValue 'PGjson (Json x) where
466+ fromValue = Json <$>
467+ Decoding.json_bytes (left Strict.Text.pack . eitherDecodeStrict)
460−instance FromValue 'PGjsonb Jsonb where
468+instance FromJSON x => FromValue 'PGjsonb (Jsonb x) where
461− fromValue = Jsonb <$> fromValue @'PGjsonb
469+ fromValue = Jsonb <$>
470+ Decoding.jsonb_bytes (left Strict.Text.pack . eitherDecodeStrict)
462instance FromArray ('NotNull ('PGvararray ty)) y
471instance FromArray ('NotNull ('PGvararray ty)) y
463 => FromValue ('PGvararray ty) y where
472 => FromValue ('PGvararray ty) y where
464 fromValue = Decoding.array (fromArray @('NotNull ('PGvararray ty)) @y)
473 fromValue = Decoding.array (fromArray @('NotNull ('PGvararray ty)) @y)
@@ -488,7 +497,7 @@ instance
488 Decoding.enum
497 Decoding.enum
489 $ fmap to
498 $ fmap to
490 . greadConstructor (constructorInfo (datatypeInfo (Proxy @y)))
499 . greadConstructor (constructorInfo (datatypeInfo (Proxy @y)))
491− . Strict.unpack
500+ . Strict.Text.unpack
492instance FromValue pg y => FromValue pg (Composite y) where
501instance FromValue pg y => FromValue pg (Composite y) where
493 fromValue = Composite <$> fromValue @pg
502 fromValue = Composite <$> fromValue @pg