refactor: configDbPreRequest to QualifiedIdentifier

This commit is contained in:
steve-chavez
2021-05-30 16:48:08 -05:00
committed by Steve Chavez
parent 5c75f0dcc2
commit 823348a72a
5 changed files with 34 additions and 15 deletions
+14
View File
@@ -6,9 +6,12 @@ module PostgREST.DbStructure.Identifiers
, Schema
, TableName
, FieldName
, toQi
) where
import qualified Data.Aeson as JSON
import qualified Data.Text as T
import qualified GHC.Show
import Protolude
@@ -23,6 +26,17 @@ data QualifiedIdentifier = QualifiedIdentifier
instance Hashable QualifiedIdentifier
instance Show QualifiedIdentifier where
show (QualifiedIdentifier s i) =
(if T.null s then mempty else toS s <> ".") <> toS i
-- TODO: Handle a case where the QI comes like this: "my.fav.schema"."my.identifier"
-- Right now it only handles the schema.identifier case
toQi :: Text -> QualifiedIdentifier
toQi txt = case T.drop 1 <$> T.breakOn "." txt of
(i, "") -> QualifiedIdentifier mempty i
(s, i) -> QualifiedIdentifier s i
type Schema = Text
type TableName = Text
type FieldName = Text