Merge pull request #80 from begriffs/empty-response

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