Uses qualified column name in order by clause to allow computed columns
This commit is contained in:
@@ -200,6 +200,17 @@ requestToQuery schema (DbRead (Node (Select colSelects tbls conditions ord, (mai
|
|||||||
("WHERE " <> intercalate " AND " ( map (pgFmtCondition qi ) conditions )) `emptyOnNull` conditions,
|
("WHERE " <> intercalate " AND " ( map (pgFmtCondition qi ) conditions )) `emptyOnNull` conditions,
|
||||||
orderF (fromMaybe [] ord)
|
orderF (fromMaybe [] ord)
|
||||||
]
|
]
|
||||||
|
orderF ts =
|
||||||
|
if null ts
|
||||||
|
then ""
|
||||||
|
else "ORDER BY " <> clause
|
||||||
|
where
|
||||||
|
clause = intercalate "," (map queryTerm ts)
|
||||||
|
queryTerm :: OrderTerm -> Text
|
||||||
|
queryTerm t = " "
|
||||||
|
<> cs (pgFmtColumn qi $ otTerm t) <> " "
|
||||||
|
<> (cs.show) (otDirection t) <> " "
|
||||||
|
<> maybe "" (cs.show) (otNullOrder t) <> " "
|
||||||
(withs, selects) = foldr getQueryParts ([],[]) forest
|
(withs, selects) = foldr getQueryParts ([],[]) forest
|
||||||
getQueryParts :: Tree ReadNode -> ([(SqlFragment, Text)], [SqlFragment]) -> ([(SqlFragment,Text)], [SqlFragment])
|
getQueryParts :: Tree ReadNode -> ([(SqlFragment, Text)], [SqlFragment]) -> ([(SqlFragment,Text)], [SqlFragment])
|
||||||
getQueryParts (Node n@(_, (table, Just (Relation {relType=Child}))) forst) (w,s) = (w,sel:s)
|
getQueryParts (Node n@(_, (table, Just (Relation {relType=Child}))) forst) (w,s) = (w,sel:s)
|
||||||
@@ -337,19 +348,6 @@ getJoinConditions (Relation t cols ft fcs typ lt lc1 lc2) =
|
|||||||
emptyOnNull :: Text -> [a] -> Text
|
emptyOnNull :: Text -> [a] -> Text
|
||||||
emptyOnNull val x = if null x then "" else val
|
emptyOnNull val x = if null x then "" else val
|
||||||
|
|
||||||
orderF :: [OrderTerm] -> SqlFragment
|
|
||||||
orderF ts =
|
|
||||||
if null ts
|
|
||||||
then ""
|
|
||||||
else "ORDER BY " <> clause
|
|
||||||
where
|
|
||||||
clause = intercalate "," (map queryTerm ts)
|
|
||||||
queryTerm :: OrderTerm -> Text
|
|
||||||
queryTerm t = " "
|
|
||||||
<> cs (pgFmtIdent $ otTerm t) <> " "
|
|
||||||
<> (cs.show) (otDirection t) <> " "
|
|
||||||
<> maybe "" (cs.show) (otNullOrder t) <> " "
|
|
||||||
|
|
||||||
insertableValue :: JSON.Value -> SqlFragment
|
insertableValue :: JSON.Value -> SqlFragment
|
||||||
insertableValue JSON.Null = "null"
|
insertableValue JSON.Null = "null"
|
||||||
insertableValue v = (<> "::unknown") . pgFmtLit $ unquoted v
|
insertableValue v = (<> "::unknown") . pgFmtLit $ unquoted v
|
||||||
|
|||||||
@@ -130,7 +130,11 @@ spec =
|
|||||||
[json| [{"text_search_vector":"'baz':1 'qux':2"}] |]
|
[json| [{"text_search_vector":"'baz':1 'qux':2"}] |]
|
||||||
|
|
||||||
it "matches with computed column" $
|
it "matches with computed column" $
|
||||||
get "/items?always_true=eq.true" `shouldRespondWith`
|
get "/items?always_true=eq.true&order=id.asc" `shouldRespondWith`
|
||||||
|
[json| [{"id":1},{"id":2},{"id":3},{"id":4},{"id":5},{"id":6},{"id":7},{"id":8},{"id":9},{"id":10},{"id":11},{"id":12},{"id":13},{"id":14},{"id":15}] |]
|
||||||
|
|
||||||
|
it "order by computed column" $
|
||||||
|
get "/items?order=always_true.asc,id.asc" `shouldRespondWith`
|
||||||
[json| [{"id":1},{"id":2},{"id":3},{"id":4},{"id":5},{"id":6},{"id":7},{"id":8},{"id":9},{"id":10},{"id":11},{"id":12},{"id":13},{"id":14},{"id":15}] |]
|
[json| [{"id":1},{"id":2},{"id":3},{"id":4},{"id":5},{"id":6},{"id":7},{"id":8},{"id":9},{"id":10},{"id":11},{"id":12},{"id":13},{"id":14},{"id":15}] |]
|
||||||
|
|
||||||
it "matches filtering nested items" $
|
it "matches filtering nested items" $
|
||||||
|
|||||||
Reference in New Issue
Block a user