From e40dcb13245d397ea4c0dc149d1af191095a0e4d Mon Sep 17 00:00:00 2001 From: Ruslan Talpa Date: Fri, 23 Oct 2015 12:53:31 +0300 Subject: [PATCH] simplify operator formatting function --- src/PostgREST/PgQuery.hs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/PostgREST/PgQuery.hs b/src/PostgREST/PgQuery.hs index 1ea572a59..62cb78327 100644 --- a/src/PostgREST/PgQuery.hs +++ b/src/PostgREST/PgQuery.hs @@ -72,6 +72,7 @@ import qualified Network.HTTP.Types.URI as Net import Text.Regex.TDFA ((=~)) import Prelude +import qualified Data.Map as M type PStmt = H.Stmt P.Postgres instance Monoid PStmt where @@ -86,6 +87,24 @@ data JsonbPath = | DoubleArrow JsonbPath JsonbPath deriving (Show) +operators :: M.Map T.Text T.Text +operators = M.fromList [ + ("eq", "="), + ("gt", ">"), + ("lt", "<"), + ("gte", ">="), + ("lte", "<="), + ("neq", "<>"), + ("like", "like"), + ("ilike", "ilike"), + ("in", "in"), + ("notin", "not in"), + ("is", "is"), + ("isnot", "is not"), + ("@@", "@@") + ] + + whereT :: QualifiedIdentifier -> Net.Query -> StatementT whereT table params q = if L.null cols @@ -323,22 +342,7 @@ pgFmtValue opCode val = unknownLiteral = (<> "::unknown ") . pgFmtLit pgFmtOperator :: T.Text -> T.Text -pgFmtOperator opCode = - case opCode of - "eq" -> "=" - "gt" -> ">" - "lt" -> "<" - "gte" -> ">=" - "lte" -> "<=" - "neq" -> "<>" - "like"-> "like" - "ilike"-> "ilike" - "in" -> "in" - "notin" -> "not in" - "is" -> "is" - "isnot" -> "is not" - "@@" -> "@@" - _ -> "=" +pgFmtOperator opCode = fromMaybe "=" $ M.lookup opCode operators pgFmtJsonbPath :: QualifiedIdentifier -> T.Text -> T.Text pgFmtJsonbPath table p =