refactor: move dumpQi to Config.hs and clarify quoteQi
The `dumpQi` function is only used in the `Config.hs` module, so it is moved there. This also adds a doctest for `quoteQi` and clarifies its usage. Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
committed by
Steve Chavez
parent
a688878236
commit
db2be093b5
@@ -63,7 +63,7 @@ import PostgREST.Config.JSPath (FilterExp (..), JSPath,
|
|||||||
pRoleClaimKey)
|
pRoleClaimKey)
|
||||||
import PostgREST.Config.Proxy (Proxy (..),
|
import PostgREST.Config.Proxy (Proxy (..),
|
||||||
isMalformedProxyUri, toURI)
|
isMalformedProxyUri, toURI)
|
||||||
import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier, dumpQi,
|
import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..),
|
||||||
toQi)
|
toQi)
|
||||||
|
|
||||||
import Protolude hiding (Proxy, toList)
|
import Protolude hiding (Proxy, toList)
|
||||||
@@ -198,6 +198,10 @@ toText conf =
|
|||||||
-- quote strings and replace " with \"
|
-- quote strings and replace " with \"
|
||||||
q s = "\"" <> T.replace "\"" "\\\"" s <> "\""
|
q s = "\"" <> T.replace "\"" "\\\"" s <> "\""
|
||||||
|
|
||||||
|
dumpQi :: QualifiedIdentifier -> Text
|
||||||
|
dumpQi (QualifiedIdentifier s i) =
|
||||||
|
(if T.null s then mempty else s <> ".") <> i
|
||||||
|
|
||||||
showTxEnd c = case (configDbTxRollbackAll c, configDbTxAllowOverride c) of
|
showTxEnd c = case (configDbTxRollbackAll c, configDbTxAllowOverride c) of
|
||||||
( False, False ) -> "commit"
|
( False, False ) -> "commit"
|
||||||
( False, True ) -> "commit-allow-override"
|
( False, True ) -> "commit-allow-override"
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ module PostgREST.SchemaCache.Identifiers
|
|||||||
, RelIdentifier(..)
|
, RelIdentifier(..)
|
||||||
, Schema
|
, Schema
|
||||||
, TableName
|
, TableName
|
||||||
, dumpQi
|
|
||||||
, escapeIdent
|
, escapeIdent
|
||||||
, isAnyElement
|
, isAnyElement
|
||||||
, quoteQi
|
, quoteQi
|
||||||
@@ -38,10 +37,12 @@ instance Hashable QualifiedIdentifier
|
|||||||
isAnyElement :: QualifiedIdentifier -> Bool
|
isAnyElement :: QualifiedIdentifier -> Bool
|
||||||
isAnyElement y = QualifiedIdentifier "pg_catalog" "anyelement" == y
|
isAnyElement y = QualifiedIdentifier "pg_catalog" "anyelement" == y
|
||||||
|
|
||||||
dumpQi :: QualifiedIdentifier -> Text
|
-- |
|
||||||
dumpQi (QualifiedIdentifier s i) =
|
-- Quote the qualified identifier when preparing the SQL. This avoids parse
|
||||||
(if T.null s then mempty else s <> ".") <> i
|
-- errors by postgres, for example on pg reserved words like "true" or "select".
|
||||||
|
--
|
||||||
|
-- >>> quoteQi (QualifiedIdentifier "" "true")
|
||||||
|
-- "\"true\""
|
||||||
quoteQi :: QualifiedIdentifier -> Text
|
quoteQi :: QualifiedIdentifier -> Text
|
||||||
quoteQi (QualifiedIdentifier s i) =
|
quoteQi (QualifiedIdentifier s i) =
|
||||||
(if T.null s then mempty else escapeIdent s <> ".") <> escapeIdent i
|
(if T.null s then mempty else escapeIdent s <> ".") <> escapeIdent i
|
||||||
|
|||||||
@@ -23,4 +23,5 @@ main =
|
|||||||
, "src/PostgREST/Query/SqlFragment.hs"
|
, "src/PostgREST/Query/SqlFragment.hs"
|
||||||
, "src/PostgREST/Response.hs"
|
, "src/PostgREST/Response.hs"
|
||||||
, "src/PostgREST/Response/Performance.hs"
|
, "src/PostgREST/Response/Performance.hs"
|
||||||
|
, "src/PostgREST/SchemaCache/Identifiers.hs"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user