Allow using nulls order without explicit order direction, fix #552

This commit is contained in:
SteveBash
2016-10-04 16:11:19 -05:00
parent 9b7685e5d1
commit 50ae48295d
5 changed files with 19 additions and 6 deletions
+1
View File
@@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed ### Fixed
- Do not apply limit to parent items - @ruslantalpa - Do not apply limit to parent items - @ruslantalpa
- Customize content negotiation per route - @begriffs - Customize content negotiation per route - @begriffs
- Allow using nulls order without explicit order direction - @steve-chavez
### Changed ### Changed
- Use HTTP 400 for raise\_exception - @begriffs - Use HTTP 400 for raise\_exception - @begriffs
+5 -4
View File
@@ -137,13 +137,14 @@ pOrderTerm :: Parser OrderTerm
pOrderTerm = pOrderTerm =
try ( do try ( do
c <- pFieldName c <- pFieldName
_ <- pDelimiter d <- optionMaybe (try $ pDelimiter *> (
d <- (string "asc" *> pure OrderAsc) try(string "asc" *> pure OrderAsc)
<|> (string "desc" *> pure OrderDesc) <|> try(string "desc" *> pure OrderDesc)
))
nls <- optionMaybe (pDelimiter *> ( nls <- optionMaybe (pDelimiter *> (
try(string "nullslast" *> pure OrderNullsLast) try(string "nullslast" *> pure OrderNullsLast)
<|> try(string "nullsfirst" *> pure OrderNullsFirst) <|> try(string "nullsfirst" *> pure OrderNullsFirst)
)) ))
return $ OrderTerm c d nls return $ OrderTerm c d nls
) )
<|> OrderTerm <$> (toS <$> pFieldName) <*> pure OrderAsc <*> pure Nothing <|> OrderTerm <$> (toS <$> pFieldName) <*> pure Nothing <*> pure Nothing
+1 -1
View File
@@ -307,7 +307,7 @@ requestToQuery schema isParent (DbRead (Node (Select colSelects tbls conditions
queryTerm :: OrderTerm -> Text queryTerm :: OrderTerm -> Text
queryTerm t = " " queryTerm t = " "
<> toS (pgFmtColumn qi $ otTerm t) <> " " <> toS (pgFmtColumn qi $ otTerm t) <> " "
<> show (otDirection t) <> " " <> maybe "" show (otDirection t) <> " "
<> maybe "" show (otNullOrder t) <> " " <> maybe "" show (otNullOrder t) <> " "
(joins, selects) = foldr getQueryParts ([],[]) forest (joins, selects) = foldr getQueryParts ([],[]) forest
+1 -1
View File
@@ -78,7 +78,7 @@ instance Show OrderNulls where
data OrderTerm = OrderTerm { data OrderTerm = OrderTerm {
otTerm :: Text otTerm :: Text
, otDirection :: OrderDirection , otDirection :: Maybe OrderDirection
, otNullOrder :: Maybe OrderNulls , otNullOrder :: Maybe OrderNulls
} deriving (Show, Eq) } deriving (Show, Eq)
+11
View File
@@ -333,6 +333,17 @@ spec = do
, matchHeaders = ["Content-Range" <:> "0-1/*"] , matchHeaders = ["Content-Range" <:> "0-1/*"]
} }
it "by a column with nulls first" $
get "/no_pk?order=a.nullsfirst"
`shouldRespondWith` ResponseMatcher {
matchBody = Just [json| [{"a":null,"b":null},
{"a":"1","b":"0"},
{"a":"2","b":"0"}
] |]
, matchStatus = 200
, matchHeaders = ["Content-Range" <:> "0-2/*"]
}
it "by a column asc with nulls last" $ it "by a column asc with nulls last" $
get "/no_pk?order=a.asc.nullslast" get "/no_pk?order=a.asc.nullslast"
`shouldRespondWith` ResponseMatcher { `shouldRespondWith` ResponseMatcher {