diff --git a/src/PostgREST/Config.hs b/src/PostgREST/Config.hs index f6e6fea89..93a429d23 100644 --- a/src/PostgREST/Config.hs +++ b/src/PostgREST/Config.hs @@ -134,7 +134,7 @@ toText conf = ,("db-config", q . T.toLower . show . configDbConfig) ,("db-tx-end", q . showTxEnd) ,("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) ,("jwt-aud", toS . encode . maybe "" toJSON . configJwtAudience) ,("jwt-role-claim-key", q . T.intercalate mempty . fmap show . configJwtRoleClaimKey) @@ -168,6 +168,9 @@ toText conf = secret = fromMaybe mempty $ configJwtSecret c showSocketMode c = showOct (configServerUnixSocketMode c) mempty + innerJoin JTInner = "inner" + innerJoin JTLeft = "left" + -- This class is needed for the polymorphism of overrideFromDbOrEnvironment -- because C.required and C.optional have different signatures class JustIfMaybe a b where diff --git a/src/PostgREST/Query/SqlFragment.hs b/src/PostgREST/Query/SqlFragment.hs index 15adacfaf..b0236fa0f 100644 --- a/src/PostgREST/Query/SqlFragment.hs +++ b/src/PostgREST/Query/SqlFragment.hs @@ -52,6 +52,7 @@ import PostgREST.DbStructure.Identifiers (FieldName, import PostgREST.RangeQuery (NonnegRange, allRange, rangeLimit, rangeOffset) import PostgREST.Request.Types (Alias, Field, Filter (..), + OrderNulls(..), OrderDirection(..), LogicOperator(..), JoinCondition (..), JsonOperand (..), JsonOperation (..), @@ -216,8 +217,15 @@ pgFmtOrderTerm :: QualifiedIdentifier -> OrderTerm -> SQL.Snippet pgFmtOrderTerm qi ot = pgFmtField qi (otTerm ot) <> " " <> SQL.sql (BS.unwords [ - BS.pack $ maybe mempty show $ otDirection ot, - BS.pack $ maybe mempty show $ otNullOrder ot]) + maybe mempty direction $ otDirection 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 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 pgFmtLogicTree :: QualifiedIdentifier -> LogicTree -> SQL.Snippet -pgFmtLogicTree qi (Expr hasNot op forest) = SQL.sql notOp <> " (" <> intercalateSnippet (" " <> BS.pack (show op) <> " ") (pgFmtLogicTree qi <$> forest) <> ")" - where notOp = if hasNot then "NOT" else mempty +pgFmtLogicTree qi (Expr hasNot op forest) = SQL.sql notOp <> " (" <> intercalateSnippet (opSql op) (pgFmtLogicTree qi <$> forest) <> ")" + where + notOp = if hasNot then "NOT" else mempty + + opSql And = " AND " + opSql Or = " OR " pgFmtLogicTree qi (Stmnt flt) = pgFmtFilter qi flt pgFmtJsonPath :: JsonPath -> SQL.Snippet diff --git a/src/PostgREST/Request/Types.hs b/src/PostgREST/Request/Types.hs index 6acbb4cbd..939d9b198 100644 --- a/src/PostgREST/Request/Types.hs +++ b/src/PostgREST/Request/Types.hs @@ -39,8 +39,6 @@ import qualified Data.Set as S import Data.Tree (Tree (..)) -import qualified GHC.Show (show) - import PostgREST.DbStructure.Identifiers (FieldName, QualifiedIdentifier) import PostgREST.DbStructure.Proc (ProcParam (..)) @@ -93,19 +91,11 @@ data OrderDirection | OrderDesc deriving (Eq) -instance Show OrderDirection where - show OrderAsc = "ASC" - show OrderDesc = "DESC" - data OrderNulls = OrderNullsFirst | OrderNullsLast deriving (Eq) -instance Show OrderNulls where - show OrderNullsFirst = "NULLS FIRST" - show OrderNullsLast = "NULLS LAST" - data MutateQuery = Insert { in_ :: QualifiedIdentifier @@ -160,9 +150,6 @@ data JoinType = JTInner | JTLeft 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 -- ["clients", "projects"] @@ -209,10 +196,6 @@ data LogicOperator | Or deriving Eq -instance Show LogicOperator where - show And = "AND" - show Or = "OR" - data Filter = Filter { field :: Field , opExpr :: OpExpr