Adds not as a keyword that can optionally be prepended to any operator in a parameter value
This commit is contained in:
@@ -182,14 +182,17 @@ callProc qi params = do
|
|||||||
|
|
||||||
wherePred :: QualifiedIdentifier -> Net.QueryItem -> PStmt
|
wherePred :: QualifiedIdentifier -> Net.QueryItem -> PStmt
|
||||||
wherePred table (col, predicate) =
|
wherePred table (col, predicate) =
|
||||||
B.Stmt (" " <> pgFmtJsonbPath table (cs col) <> " " <> op <> " " <>
|
B.Stmt (notOp <> " " <> pgFmtJsonbPath table (cs col) <> " " <> op <> " " <>
|
||||||
if opCode `elem` ["is","isnot"] then whiteList value
|
if opCode `elem` ["is","isnot"] then whiteList value
|
||||||
else cs sqlValue)
|
else cs sqlValue)
|
||||||
empty True
|
empty True
|
||||||
|
|
||||||
where
|
where
|
||||||
opCode:rest = T.split (=='.') $ cs $ fromMaybe "." predicate
|
headPredicate:rest = T.split (=='.') $ cs $ fromMaybe "." predicate
|
||||||
value = T.intercalate "." rest
|
hasNot caseTrue caseFalse = if headPredicate == "not" then caseTrue else caseFalse
|
||||||
|
opCode = hasNot (head rest) headPredicate
|
||||||
|
notOp = hasNot headPredicate ""
|
||||||
|
value = hasNot (T.intercalate "." $ tail rest) (T.intercalate "." rest)
|
||||||
whiteList val = fromMaybe (cs (pgFmtLit val) <> "::unknown ")
|
whiteList val = fromMaybe (cs (pgFmtLit val) <> "::unknown ")
|
||||||
(L.find ((==) . T.toLower $ val)
|
(L.find ((==) . T.toLower $ val)
|
||||||
["null","true","false"])
|
["null","true","false"])
|
||||||
|
|||||||
@@ -53,6 +53,14 @@ spec =
|
|||||||
, matchHeaders = ["Content-Range" <:> "0-2/3"]
|
, matchHeaders = ["Content-Range" <:> "0-2/3"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it "matches items NOT IN using not operator" $
|
||||||
|
get "/items?id=not.in.2,4,6,7,8,9,10,11,12,13,14,15"
|
||||||
|
`shouldRespondWith` ResponseMatcher {
|
||||||
|
matchBody = Just [json| [{"id":1},{"id":3},{"id":5}] |]
|
||||||
|
, matchStatus = 200
|
||||||
|
, matchHeaders = ["Content-Range" <:> "0-2/3"]
|
||||||
|
}
|
||||||
|
|
||||||
it "matches nulls in varchar and numeric fields alike" $ do
|
it "matches nulls in varchar and numeric fields alike" $ do
|
||||||
get "/no_pk?a=is.null" `shouldRespondWith`
|
get "/no_pk?a=is.null" `shouldRespondWith`
|
||||||
[json| [{"a": null, "b": null}] |]
|
[json| [{"a": null, "b": null}] |]
|
||||||
@@ -166,12 +174,15 @@ spec =
|
|||||||
respHeaders `shouldSatisfy` matchHeader
|
respHeaders `shouldSatisfy` matchHeader
|
||||||
"Content-Location" "/simple_pk"
|
"Content-Location" "/simple_pk"
|
||||||
|
|
||||||
describe "jsonb" $
|
describe "jsonb" $ do
|
||||||
it "can filter by properties inside json column" $ do
|
it "can filter by properties inside json column" $ do
|
||||||
get "/json?data->foo->>bar=eq.baz" `shouldRespondWith`
|
get "/json?data->foo->>bar=eq.baz" `shouldRespondWith`
|
||||||
[json| [{"data": {"foo": {"bar": "baz"}}}] |]
|
[json| [{"data": {"foo": {"bar": "baz"}}}] |]
|
||||||
get "/json?data->foo->>bar=eq.fake" `shouldRespondWith`
|
get "/json?data->foo->>bar=eq.fake" `shouldRespondWith`
|
||||||
[json| [] |]
|
[json| [] |]
|
||||||
|
it "can filter by properties inside json column using not" $
|
||||||
|
get "/json?data->foo->>bar=not.eq.baz" `shouldRespondWith`
|
||||||
|
[json| [] |]
|
||||||
|
|
||||||
describe "remote procedure call" $ do
|
describe "remote procedure call" $ do
|
||||||
context "a proc that returns a set" . before_ (clearTable "items" >> createItems 10) .
|
context "a proc that returns a set" . before_ (clearTable "items" >> createItems 10) .
|
||||||
|
|||||||
Reference in New Issue
Block a user