Prepared statement for set_config
This commit is contained in:
committed by
Steve Chavez
parent
7069bb3c01
commit
11d62a8010
@@ -5,10 +5,13 @@ Description : Common helper functions.
|
||||
module PostgREST.Private.Common where
|
||||
|
||||
import Data.Maybe
|
||||
import qualified Hasql.Decoders as HD
|
||||
import qualified Hasql.Encoders as HE
|
||||
import qualified Hasql.Decoders as HD
|
||||
import qualified Hasql.DynamicStatements.Snippet as H
|
||||
import qualified Hasql.Encoders as HE
|
||||
import Protolude
|
||||
|
||||
import Data.Foldable (foldr1)
|
||||
|
||||
column :: HD.Value a -> HD.Row a
|
||||
column = HD.column . HD.nonNullable
|
||||
|
||||
@@ -23,3 +26,10 @@ param = HE.param . HE.nonNullable
|
||||
|
||||
arrayParam :: HE.Value a -> HE.Params [a]
|
||||
arrayParam = param . HE.array . HE.dimension foldl' . HE.element . HE.nonNullable
|
||||
|
||||
emptySnippetOnFalse :: H.Snippet -> Bool -> H.Snippet
|
||||
emptySnippetOnFalse val cond = if cond then mempty else val
|
||||
|
||||
intercalateSnippet :: ByteString -> [H.Snippet] -> H.Snippet
|
||||
intercalateSnippet _ [] = mempty
|
||||
intercalateSnippet frag snippets = foldr1 (\a b -> a <> H.sql frag <> b) snippets
|
||||
|
||||
@@ -30,9 +30,8 @@ import Protolude hiding (cast,
|
||||
import Protolude.Conv (toS)
|
||||
import Text.InterpolatedString.Perl6 (qc)
|
||||
|
||||
import qualified Hasql.Encoders as HE
|
||||
|
||||
import Data.Foldable (foldr1)
|
||||
import qualified Hasql.Encoders as HE
|
||||
import PostgREST.Private.Common
|
||||
|
||||
noLocationF :: SqlFragment
|
||||
noLocationF = "array[]::text[]"
|
||||
@@ -250,10 +249,3 @@ unknownEncoder = H.encoderAndParam (HE.nonNullable HE.unknown)
|
||||
|
||||
unknownLiteral :: Text -> H.Snippet
|
||||
unknownLiteral = unknownEncoder . encodeUtf8
|
||||
|
||||
emptySnippetOnFalse :: H.Snippet -> Bool -> H.Snippet
|
||||
emptySnippetOnFalse val cond = if cond then mempty else val
|
||||
|
||||
intercalateSnippet :: SqlFragment -> [H.Snippet] -> H.Snippet
|
||||
intercalateSnippet _ [] = mempty
|
||||
intercalateSnippet frag snippets = foldr1 (\a b -> a <> H.sql frag <> b) snippets
|
||||
|
||||
Reference in New Issue
Block a user