refactor: Remove GHC.Show instances from Request.Types module

This commit is contained in:
monacoremo
2021-11-09 19:13:52 +01:00
committed by Remo
parent 038d84b62d
commit 5dc37fc8e8
3 changed files with 20 additions and 22 deletions
+4 -1
View File
@@ -134,7 +134,7 @@ toText conf =
,("db-config", q . T.toLower . show . configDbConfig) ,("db-config", q . T.toLower . show . configDbConfig)
,("db-tx-end", q . showTxEnd) ,("db-tx-end", q . showTxEnd)
,("db-uri", q . configDbUri) ,("db-uri", q . configDbUri)
,("db-embed-default-join", q . show . configDbEmbedDefaultJoin) ,("db-embed-default-join", q . innerJoin . configDbEmbedDefaultJoin)
,("db-use-legacy-gucs", T.toLower . show . configDbUseLegacyGucs) ,("db-use-legacy-gucs", T.toLower . show . configDbUseLegacyGucs)
,("jwt-aud", toS . encode . maybe "" toJSON . configJwtAudience) ,("jwt-aud", toS . encode . maybe "" toJSON . configJwtAudience)
,("jwt-role-claim-key", q . T.intercalate mempty . fmap show . configJwtRoleClaimKey) ,("jwt-role-claim-key", q . T.intercalate mempty . fmap show . configJwtRoleClaimKey)
@@ -168,6 +168,9 @@ toText conf =
secret = fromMaybe mempty $ configJwtSecret c secret = fromMaybe mempty $ configJwtSecret c
showSocketMode c = showOct (configServerUnixSocketMode c) mempty showSocketMode c = showOct (configServerUnixSocketMode c) mempty
innerJoin JTInner = "inner"
innerJoin JTLeft = "left"
-- This class is needed for the polymorphism of overrideFromDbOrEnvironment -- This class is needed for the polymorphism of overrideFromDbOrEnvironment
-- because C.required and C.optional have different signatures -- because C.required and C.optional have different signatures
class JustIfMaybe a b where class JustIfMaybe a b where
+16 -4
View File
@@ -52,6 +52,7 @@ import PostgREST.DbStructure.Identifiers (FieldName,
import PostgREST.RangeQuery (NonnegRange, allRange, import PostgREST.RangeQuery (NonnegRange, allRange,
rangeLimit, rangeOffset) rangeLimit, rangeOffset)
import PostgREST.Request.Types (Alias, Field, Filter (..), import PostgREST.Request.Types (Alias, Field, Filter (..),
OrderNulls(..), OrderDirection(..), LogicOperator(..),
JoinCondition (..), JoinCondition (..),
JsonOperand (..), JsonOperand (..),
JsonOperation (..), JsonOperation (..),
@@ -216,8 +217,15 @@ pgFmtOrderTerm :: QualifiedIdentifier -> OrderTerm -> SQL.Snippet
pgFmtOrderTerm qi ot = pgFmtOrderTerm qi ot =
pgFmtField qi (otTerm ot) <> " " <> pgFmtField qi (otTerm ot) <> " " <>
SQL.sql (BS.unwords [ SQL.sql (BS.unwords [
BS.pack $ maybe mempty show $ otDirection ot, maybe mempty direction $ otDirection ot,
BS.pack $ maybe mempty show $ otNullOrder ot]) maybe mempty nullOrder $ otNullOrder ot])
where
direction OrderAsc = "ASC"
direction OrderDesc = "DESC"
nullOrder OrderNullsFirst = "NULLS FIRST"
nullOrder OrderNullsLast = "NULLS LAST"
pgFmtFilter :: QualifiedIdentifier -> Filter -> SQL.Snippet pgFmtFilter :: QualifiedIdentifier -> Filter -> SQL.Snippet
pgFmtFilter table (Filter fld (OpExpr hasNot oper)) = notOp <> " " <> case oper of pgFmtFilter table (Filter fld (OpExpr hasNot oper)) = notOp <> " " <> case oper of
@@ -255,8 +263,12 @@ pgFmtJoinCondition (JoinCondition (qi1, col1) (qi2, col2)) =
SQL.sql $ pgFmtColumn qi1 col1 <> " = " <> pgFmtColumn qi2 col2 SQL.sql $ pgFmtColumn qi1 col1 <> " = " <> pgFmtColumn qi2 col2
pgFmtLogicTree :: QualifiedIdentifier -> LogicTree -> SQL.Snippet pgFmtLogicTree :: QualifiedIdentifier -> LogicTree -> SQL.Snippet
pgFmtLogicTree qi (Expr hasNot op forest) = SQL.sql notOp <> " (" <> intercalateSnippet (" " <> BS.pack (show op) <> " ") (pgFmtLogicTree qi <$> forest) <> ")" pgFmtLogicTree qi (Expr hasNot op forest) = SQL.sql notOp <> " (" <> intercalateSnippet (opSql op) (pgFmtLogicTree qi <$> forest) <> ")"
where notOp = if hasNot then "NOT" else mempty where
notOp = if hasNot then "NOT" else mempty
opSql And = " AND "
opSql Or = " OR "
pgFmtLogicTree qi (Stmnt flt) = pgFmtFilter qi flt pgFmtLogicTree qi (Stmnt flt) = pgFmtFilter qi flt
pgFmtJsonPath :: JsonPath -> SQL.Snippet pgFmtJsonPath :: JsonPath -> SQL.Snippet
-17
View File
@@ -39,8 +39,6 @@ import qualified Data.Set as S
import Data.Tree (Tree (..)) import Data.Tree (Tree (..))
import qualified GHC.Show (show)
import PostgREST.DbStructure.Identifiers (FieldName, import PostgREST.DbStructure.Identifiers (FieldName,
QualifiedIdentifier) QualifiedIdentifier)
import PostgREST.DbStructure.Proc (ProcParam (..)) import PostgREST.DbStructure.Proc (ProcParam (..))
@@ -93,19 +91,11 @@ data OrderDirection
| OrderDesc | OrderDesc
deriving (Eq) deriving (Eq)
instance Show OrderDirection where
show OrderAsc = "ASC"
show OrderDesc = "DESC"
data OrderNulls data OrderNulls
= OrderNullsFirst = OrderNullsFirst
| OrderNullsLast | OrderNullsLast
deriving (Eq) deriving (Eq)
instance Show OrderNulls where
show OrderNullsFirst = "NULLS FIRST"
show OrderNullsLast = "NULLS LAST"
data MutateQuery data MutateQuery
= Insert = Insert
{ in_ :: QualifiedIdentifier { in_ :: QualifiedIdentifier
@@ -160,9 +150,6 @@ data JoinType
= JTInner = JTInner
| JTLeft | JTLeft
deriving Eq deriving Eq
instance Show JoinType where
show JTInner = "inner"
show JTLeft = "left"
-- | Path of the embedded levels, e.g "clients.projects.name=eq.." gives Path -- | Path of the embedded levels, e.g "clients.projects.name=eq.." gives Path
-- ["clients", "projects"] -- ["clients", "projects"]
@@ -209,10 +196,6 @@ data LogicOperator
| Or | Or
deriving Eq deriving Eq
instance Show LogicOperator where
show And = "AND"
show Or = "OR"
data Filter = Filter data Filter = Filter
{ field :: Field { field :: Field
, opExpr :: OpExpr , opExpr :: OpExpr