Merge branch 'jcristovao-isnull'
This commit is contained in:
+2
-1
@@ -5,7 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
### Added
|
### Added
|
||||||
- Option to specify nulls first or last, eg /people?order=age.desc.nullsfirst
|
- Option to specify nulls first or last, eg `/people?order=age.desc.nullsfirst`
|
||||||
|
- Filter nulls, `?col=is.null` and `?col=isnot.null`
|
||||||
|
|
||||||
## [0.2.7.0] - 2015-03-03
|
## [0.2.7.0] - 2015-03-03
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
+10
-3
@@ -139,13 +139,18 @@ update t cols vals = B.Stmt
|
|||||||
empty True
|
empty True
|
||||||
|
|
||||||
wherePred :: Net.QueryItem -> PStmt
|
wherePred :: Net.QueryItem -> PStmt
|
||||||
wherePred (col, predicate) = B.Stmt
|
wherePred (col, predicate) =
|
||||||
(" " <> cs (pgFmtIdent $ cs col) <> " " <> op <> " " <> cs sqlValue)
|
B.Stmt (" " <> cs (pgFmtIdent $ cs col) <> " " <> op <> " " <>
|
||||||
empty True
|
if opCode `elem` ["is","isnot"] then whiteList value
|
||||||
|
else cs sqlValue)
|
||||||
|
empty True
|
||||||
|
|
||||||
where
|
where
|
||||||
opCode:rest = T.split (=='.') $ cs $ fromMaybe "." predicate
|
opCode:rest = T.split (=='.') $ cs $ fromMaybe "." predicate
|
||||||
value = T.intercalate "." rest
|
value = T.intercalate "." rest
|
||||||
|
whiteList val = fromMaybe (cs (pgFmtLit val) <> "::unknown ")
|
||||||
|
(L.find ((==) . T.toLower $ val)
|
||||||
|
["null","true","false"])
|
||||||
|
|
||||||
star c = if c == '*' then '%' else c
|
star c = if c == '*' then '%' else c
|
||||||
unknownLiteral = (<> "::unknown ") . pgFmtLit
|
unknownLiteral = (<> "::unknown ") . pgFmtLit
|
||||||
@@ -166,6 +171,8 @@ wherePred (col, predicate) = B.Stmt
|
|||||||
"like"-> "like"
|
"like"-> "like"
|
||||||
"ilike"-> "ilike"
|
"ilike"-> "ilike"
|
||||||
"in" -> "in"
|
"in" -> "in"
|
||||||
|
"is" -> "is"
|
||||||
|
"isnot" -> "is not"
|
||||||
_ -> "="
|
_ -> "="
|
||||||
|
|
||||||
orderParse :: Net.Query -> [OrderTerm]
|
orderParse :: Net.Query -> [OrderTerm]
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ spec =
|
|||||||
, matchHeaders = ["Content-Range" <:> "0-2/3"]
|
, matchHeaders = ["Content-Range" <:> "0-2/3"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it "matches nulls" $
|
||||||
|
get "/no_pk?a=is.null" `shouldRespondWith`
|
||||||
|
[json| [{"a": null, "b": null}] |]
|
||||||
|
|
||||||
it "matches with like" $ do
|
it "matches with like" $ do
|
||||||
get "/simple_pk?k=like.*yx" `shouldRespondWith`
|
get "/simple_pk?k=like.*yx" `shouldRespondWith`
|
||||||
"[{\"k\":\"xyyx\",\"extra\":\"u\"}]"
|
"[{\"k\":\"xyyx\",\"extra\":\"u\"}]"
|
||||||
|
|||||||
Reference in New Issue
Block a user