Merge pull request #80 from begriffs/empty-response
Return [] rather than nothing on no results
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
name: dbapi
|
name: dbapi
|
||||||
version: 0.2.1.0
|
version: 0.2.2.0
|
||||||
synopsis: The database is your api
|
synopsis: The database is your api
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
|
|||||||
@@ -179,7 +179,6 @@ respondWithRangedResult rr =
|
|||||||
total = rrTotal rr
|
total = rrTotal rr
|
||||||
status
|
status
|
||||||
| from > total = status416
|
| from > total = status416
|
||||||
| total == 0 = status204
|
|
||||||
| (1 + to - from) < total = status206
|
| (1 + to - from) < total = status206
|
||||||
| otherwise = status200
|
| otherwise = status200
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -71,11 +71,11 @@ getRows schema table qq range conn = do
|
|||||||
r <- quickQuery conn query []
|
r <- quickQuery conn query []
|
||||||
|
|
||||||
return $ case r of
|
return $ case r of
|
||||||
[[total, _, SqlNull]] -> RangedResult offset 0 (fromSql total) ""
|
[[total, _, SqlNull]] -> RangedResult offset 0 (fromSql total) "[]"
|
||||||
[[total, limited_total, json]] ->
|
[[total, limited_total, json]] ->
|
||||||
RangedResult offset (offset + fromSql limited_total - 1)
|
RangedResult offset (offset + fromSql limited_total - 1)
|
||||||
(fromSql total) (fromSql json)
|
(fromSql total) (fromSql json)
|
||||||
_ -> RangedResult 0 0 0 ""
|
_ -> RangedResult 0 0 0 "[]"
|
||||||
|
|
||||||
where
|
where
|
||||||
offset = fromMaybe 0 $ R.offset <$> range
|
offset = fromMaybe 0 $ R.offset <$> range
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ spec = around appWithFixture $ do
|
|||||||
it "Sets Content-Location with alphabetized params" $
|
it "Sets Content-Location with alphabetized params" $
|
||||||
get "/no_pk?b=eq.1&a=eq.1"
|
get "/no_pk?b=eq.1&a=eq.1"
|
||||||
`shouldRespondWith` ResponseMatcher {
|
`shouldRespondWith` ResponseMatcher {
|
||||||
matchBody = Nothing
|
matchBody = Just "[]"
|
||||||
, matchStatus = 204
|
, matchStatus = 200
|
||||||
, matchHeaders = ["Content-Location" <:> "/no_pk?a=eq.1&b=eq.1"]
|
, matchHeaders = ["Content-Location" <:> "/no_pk?a=eq.1&b=eq.1"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ spec = around appWithFixture $
|
|||||||
request methodGet "/menagerie"
|
request methodGet "/menagerie"
|
||||||
(rangeHdrs $ ByteRangeFromTo 0 1) ""
|
(rangeHdrs $ ByteRangeFromTo 0 1) ""
|
||||||
`shouldRespondWith` ResponseMatcher {
|
`shouldRespondWith` ResponseMatcher {
|
||||||
matchBody = Nothing
|
matchBody = Just "[]"
|
||||||
, matchStatus = 204
|
, matchStatus = 200
|
||||||
, matchHeaders = ["Content-Range" <:> "*/0"]
|
, matchHeaders = ["Content-Range" <:> "*/0"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user