Support for &select=col1,col2,col3 as suggested in issue #227
This commit is contained in:
@@ -72,7 +72,7 @@ app conf reqBody req =
|
|||||||
. limitT range
|
. limitT range
|
||||||
. orderT (orderParse qq)
|
. orderT (orderParse qq)
|
||||||
. whereT qt qq
|
. whereT qt qq
|
||||||
$ selectStar qt
|
$ selectT qt qq
|
||||||
)
|
)
|
||||||
row <- H.maybeEx select
|
row <- H.maybeEx select
|
||||||
let (tableTotal, queryTotal, body) =
|
let (tableTotal, queryTotal, body) =
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ whereT table params q =
|
|||||||
then q
|
then q
|
||||||
else q <> B.Stmt " where " empty True <> conjunction
|
else q <> B.Stmt " where " empty True <> conjunction
|
||||||
where
|
where
|
||||||
cols = [ col | col <- params, fst col `notElem` ["order"] ]
|
cols = [ col | col <- params, fst col `notElem` ["order","select"] ]
|
||||||
wherePredTable = wherePred table
|
wherePredTable = wherePred table
|
||||||
conjunction = mconcat $ L.intersperse andq (map wherePredTable cols)
|
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 :: QualifiedIdentifier -> PStmt
|
||||||
selectStar t = B.Stmt ("select * from " <> fromQi t) empty True
|
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 :: StatementT
|
||||||
returningStarT s = s { B.stmtTemplate = B.stmtTemplate s <> " RETURNING *" }
|
returningStarT s = s { B.stmtTemplate = B.stmtTemplate s <> " RETURNING *" }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user