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:
Taimoor Zaeem
2025-10-30 12:26:29 -05:00
committed by Steve Chavez
parent a688878236
commit db2be093b5
3 changed files with 12 additions and 6 deletions
+6 -5
View File
@@ -7,7 +7,6 @@ module PostgREST.SchemaCache.Identifiers
, RelIdentifier(..)
, Schema
, TableName
, dumpQi
, escapeIdent
, isAnyElement
, quoteQi
@@ -38,10 +37,12 @@ instance Hashable QualifiedIdentifier
isAnyElement :: QualifiedIdentifier -> Bool
isAnyElement y = QualifiedIdentifier "pg_catalog" "anyelement" == y
dumpQi :: QualifiedIdentifier -> Text
dumpQi (QualifiedIdentifier s i) =
(if T.null s then mempty else s <> ".") <> i
-- |
-- Quote the qualified identifier when preparing the SQL. This avoids parse
-- errors by postgres, for example on pg reserved words like "true" or "select".
--
-- >>> quoteQi (QualifiedIdentifier "" "true")
-- "\"true\""
quoteQi :: QualifiedIdentifier -> Text
quoteQi (QualifiedIdentifier s i) =
(if T.null s then mempty else escapeIdent s <> ".") <> escapeIdent i