Support for &select=col1,col2,col3 as suggested in issue #227

This commit is contained in:
Ruslan Talpa
2015-09-02 11:03:34 +03:00
parent 3d670b9c03
commit b9fec2ce41
2 changed files with 16 additions and 2 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ app conf reqBody req =
. limitT range
. orderT (orderParse qq)
. whereT qt qq
$ selectStar qt
$ selectT qt qq
)
row <- H.maybeEx select
let (tableTotal, queryTotal, body) =
+15 -1
View File
@@ -58,7 +58,7 @@ whereT table params q =
then q
else q <> B.Stmt " where " empty True <> conjunction
where
cols = [ col | col <- params, fst col `notElem` ["order"] ]
cols = [ col | col <- params, fst col `notElem` ["order","select"] ]
wherePredTable = wherePred table
conjunction = mconcat $ L.intersperse andq (map wherePredTable cols)
@@ -129,6 +129,20 @@ asJsonRow s = s { B.stmtTemplate = "row_to_json(t) from (" <> B.stmtTemplate s <
selectStar :: QualifiedIdentifier -> PStmt
selectStar t = B.Stmt ("select * from " <> fromQi t) empty True
selectT :: QualifiedIdentifier -> Net.Query -> PStmt
selectT table params =
if L.null cols
then selectStar table
else B.Stmt "select " empty True <> conjunction <> B.Stmt (" from " <> fromQi table ) empty True
where
selectTermTable = selectTerm table
conjunction = mconcat $ L.intersperse commaq (map selectTermTable cols)
columnsParam = fromMaybe "" $ join (lookup "select" params)
cols = filter ((>0) . T.length) $ map T.strip $ T.split (==',') $ cs columnsParam
selectTerm :: QualifiedIdentifier -> T.Text -> PStmt
selectTerm table col = B.Stmt (pgFmtJsonbPath table (cs col)) empty True
returningStarT :: StatementT
returningStarT s = s { B.stmtTemplate = B.stmtTemplate s <> " RETURNING *" }