transaction-scoped settings are now shown clearly in the postgres logs
This commit is contained in:
@@ -33,8 +33,9 @@ module PostgREST.Query.SqlFragment
|
||||
, unknownEncoder
|
||||
, intercalateSnippet
|
||||
, explainF
|
||||
, setConfigLocal
|
||||
, setConfigLocalJson
|
||||
, setConfigWithConstantName
|
||||
, setConfigWithDynamicName
|
||||
, setConfigWithConstantNameJSON
|
||||
, escapeIdent
|
||||
, escapeIdentList
|
||||
) where
|
||||
@@ -484,14 +485,23 @@ explainF fmt opts snip =
|
||||
fmtPlanFmt PlanJSON = "FORMAT JSON"
|
||||
|
||||
-- | Do a pg set_config(setting, value, true) call. This is equivalent to a SET LOCAL.
|
||||
setConfigLocal :: (ByteString, ByteString) -> SQL.Snippet
|
||||
setConfigLocal :: (SQL.Snippet, ByteString) -> SQL.Snippet
|
||||
setConfigLocal (k, v) =
|
||||
"set_config(" <> unknownEncoder k <> ", " <> unknownEncoder v <> ", true)"
|
||||
"set_config(" <> k <> ", " <> unknownEncoder v <> ", true)"
|
||||
|
||||
-- | For when the settings are hardcoded and not parameterized
|
||||
setConfigWithConstantName :: (SQL.Snippet, ByteString) -> SQL.Snippet
|
||||
setConfigWithConstantName (k, v) = setConfigLocal ("'" <> k <> "'", v)
|
||||
|
||||
-- | For when the settings need to be parameterized
|
||||
setConfigWithDynamicName :: (ByteString, ByteString) -> SQL.Snippet
|
||||
setConfigWithDynamicName (k, v) =
|
||||
setConfigLocal (unknownEncoder k, v)
|
||||
|
||||
-- | Starting from PostgreSQL v14, some characters are not allowed for config names (mostly affecting headers with "-").
|
||||
-- | A JSON format string is used to avoid this problem. See https://github.com/PostgREST/postgrest/issues/1857
|
||||
setConfigLocalJson :: ByteString -> [(ByteString, ByteString)] -> [SQL.Snippet]
|
||||
setConfigLocalJson prefix keyVals = [setConfigLocal (prefix, gucJsonVal keyVals)]
|
||||
setConfigWithConstantNameJSON :: SQL.Snippet -> [(ByteString, ByteString)] -> [SQL.Snippet]
|
||||
setConfigWithConstantNameJSON prefix keyVals = [setConfigWithConstantName (prefix, gucJsonVal keyVals)]
|
||||
where
|
||||
gucJsonVal :: [(ByteString, ByteString)] -> ByteString
|
||||
gucJsonVal = LBS.toStrict . JSON.encode . HM.fromList . arrayByteStringToText
|
||||
|
||||
Reference in New Issue
Block a user