From 8c073cedc64cba1f96bc1c9cb7e2808155df4150 Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Wed, 12 Nov 2014 09:24:05 -0800 Subject: [PATCH] Add PATCH handler --- src/App.hs | 15 +++++++++------ src/PgQuery.hs | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/App.hs b/src/App.hs index 6b01eaf6d..b1199e1f3 100644 --- a/src/App.hs +++ b/src/App.hs @@ -131,6 +131,15 @@ app conn req respond = "You must specify all columns in PUT request" ) + ([table], "PATCH") -> + handleJsonObj req (\obj -> do + let qt = QualifiedTable schema (cs table) + _ <- uncurry (execute conn) + $ whereT qq + $ update qt (map cs $ keys obj) (elems obj) + return $ responseLBS status204 [ jsonH ] "" + ) + (_, _) -> return $ responseLBS status404 [] "" @@ -221,12 +230,6 @@ instance ToJSON TableOptions where -- ] "" --- ([table], "PATCH") -> --- jsonBodyAction req (\row -> do --- _ <- update ver table row qq conn --- return $ responseLBS status204 [ jsonContentType ] "" --- ) - -- (_, _) -> -- return $ responseLBS status404 [] "" diff --git a/src/PgQuery.hs b/src/PgQuery.hs index 582ac1d77..1e0de2d66 100644 --- a/src/PgQuery.hs +++ b/src/PgQuery.hs @@ -39,7 +39,7 @@ whereT :: Net.Query -> CompleteQueryT whereT params q = if L.null params then q - else q <> conjunction + else q <> (" where ",[]) <> conjunction where cols = [ col | col <- params, fst col `notElem` ["order"] ] conjunction = mconcat $ L.intersperse andq (map wherePred cols)