refactor: Remove Protolude.Conv from SqlFragment

This commit is contained in:
monacoremo
2021-11-12 20:25:22 +01:00
committed by Remo
parent 8cc8531e49
commit 3820590649
+4 -5
View File
@@ -63,8 +63,7 @@ import PostgREST.Request.Types (Alias, Field, Filter (..),
OrderNulls (..), OrderNulls (..),
OrderTerm (..), SelectItem) OrderTerm (..), SelectItem)
import Protolude hiding (cast, toS) import Protolude hiding (cast)
import Protolude.Conv (toS)
-- | A part of a SQL query that cannot be executed independently -- | A part of a SQL query that cannot be executed independently
@@ -122,14 +121,14 @@ normalizedBody body =
"END AS val", "END AS val",
"FROM pgrst_payload)"]) "FROM pgrst_payload)"])
where where
jsonPlaceHolder = SQL.encoderAndParam (HE.nullable HE.unknown) (toS <$> body) <> "::json" jsonPlaceHolder = SQL.encoderAndParam (HE.nullable HE.unknown) (LBS.toStrict <$> body) <> "::json"
singleParameter :: Maybe LBS.ByteString -> ByteString -> SQL.Snippet singleParameter :: Maybe LBS.ByteString -> ByteString -> SQL.Snippet
singleParameter body typ = singleParameter body typ =
if typ == "bytea" if typ == "bytea"
-- TODO: Hasql fails when using HE.unknown with bytea(pg tries to utf8 encode). -- TODO: Hasql fails when using HE.unknown with bytea(pg tries to utf8 encode).
then SQL.encoderAndParam (HE.nullable HE.bytea) (toS <$> body) then SQL.encoderAndParam (HE.nullable HE.bytea) (LBS.toStrict <$> body)
else SQL.encoderAndParam (HE.nullable HE.unknown) (toS <$> body) <> "::" <> SQL.sql typ else SQL.encoderAndParam (HE.nullable HE.unknown) (LBS.toStrict <$> body) <> "::" <> SQL.sql typ
selectBody :: SqlFragment selectBody :: SqlFragment
selectBody = "(SELECT val FROM pgrst_body)" selectBody = "(SELECT val FROM pgrst_body)"