From 21e4e583ec71f7176a790c712a9eb8c9ad12f4f7 Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Tue, 14 Oct 2014 11:23:26 -0700 Subject: [PATCH] Return [] rather than nothing on no results Fixes #70 --- dbapi.cabal | 2 +- src/Dbapi.hs | 1 - src/PgQuery.hs | 4 ++-- test/Feature/QuerySpec.hs | 4 ++-- test/Feature/RangeSpec.hs | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dbapi.cabal b/dbapi.cabal index adfbbba1e..0e18a171e 100644 --- a/dbapi.cabal +++ b/dbapi.cabal @@ -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 diff --git a/src/Dbapi.hs b/src/Dbapi.hs index 8df39cfe0..c04fa8be0 100644 --- a/src/Dbapi.hs +++ b/src/Dbapi.hs @@ -179,7 +179,6 @@ respondWithRangedResult rr = total = rrTotal rr status | from > total = status416 - | total == 0 = status204 | (1 + to - from) < total = status206 | otherwise = status200 diff --git a/src/PgQuery.hs b/src/PgQuery.hs index 5282b30f0..976a6bd03 100644 --- a/src/PgQuery.hs +++ b/src/PgQuery.hs @@ -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 diff --git a/test/Feature/QuerySpec.hs b/test/Feature/QuerySpec.hs index e71bed4a6..1d23da085 100644 --- a/test/Feature/QuerySpec.hs +++ b/test/Feature/QuerySpec.hs @@ -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"] } diff --git a/test/Feature/RangeSpec.hs b/test/Feature/RangeSpec.hs index 15dd6dd43..7135f162a 100644 --- a/test/Feature/RangeSpec.hs +++ b/test/Feature/RangeSpec.hs @@ -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"] }