simplify operator formatting function

This commit is contained in:
Ruslan Talpa
2015-10-23 12:53:31 +03:00
parent 826de74a5d
commit e40dcb1324
+20 -16
View File
@@ -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 =