simplify operator formatting function
This commit is contained in:
+20
-16
@@ -72,6 +72,7 @@ import qualified Network.HTTP.Types.URI as Net
|
|||||||
import Text.Regex.TDFA ((=~))
|
import Text.Regex.TDFA ((=~))
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
import qualified Data.Map as M
|
||||||
|
|
||||||
type PStmt = H.Stmt P.Postgres
|
type PStmt = H.Stmt P.Postgres
|
||||||
instance Monoid PStmt where
|
instance Monoid PStmt where
|
||||||
@@ -86,6 +87,24 @@ data JsonbPath =
|
|||||||
| DoubleArrow JsonbPath JsonbPath
|
| DoubleArrow JsonbPath JsonbPath
|
||||||
deriving (Show)
|
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 :: QualifiedIdentifier -> Net.Query -> StatementT
|
||||||
whereT table params q =
|
whereT table params q =
|
||||||
if L.null cols
|
if L.null cols
|
||||||
@@ -323,22 +342,7 @@ pgFmtValue opCode val =
|
|||||||
unknownLiteral = (<> "::unknown ") . pgFmtLit
|
unknownLiteral = (<> "::unknown ") . pgFmtLit
|
||||||
|
|
||||||
pgFmtOperator :: T.Text -> T.Text
|
pgFmtOperator :: T.Text -> T.Text
|
||||||
pgFmtOperator opCode =
|
pgFmtOperator opCode = fromMaybe "=" $ M.lookup opCode operators
|
||||||
case opCode of
|
|
||||||
"eq" -> "="
|
|
||||||
"gt" -> ">"
|
|
||||||
"lt" -> "<"
|
|
||||||
"gte" -> ">="
|
|
||||||
"lte" -> "<="
|
|
||||||
"neq" -> "<>"
|
|
||||||
"like"-> "like"
|
|
||||||
"ilike"-> "ilike"
|
|
||||||
"in" -> "in"
|
|
||||||
"notin" -> "not in"
|
|
||||||
"is" -> "is"
|
|
||||||
"isnot" -> "is not"
|
|
||||||
"@@" -> "@@"
|
|
||||||
_ -> "="
|
|
||||||
|
|
||||||
pgFmtJsonbPath :: QualifiedIdentifier -> T.Text -> T.Text
|
pgFmtJsonbPath :: QualifiedIdentifier -> T.Text -> T.Text
|
||||||
pgFmtJsonbPath table p =
|
pgFmtJsonbPath table p =
|
||||||
|
|||||||
Reference in New Issue
Block a user