WIP: call stored pprocedures that emit plain text

The beginning of #114
This commit is contained in:
Joe Nelson
2015-08-20 21:52:46 -07:00
parent f564fb0977
commit bb511f0df2
3 changed files with 38 additions and 2 deletions
+18 -1
View File
@@ -163,6 +163,21 @@ app conf reqBody req =
] $ if echoRequested then encode obj else ""
return $ multipart status201 responses
(["rpc", proc], "POST") -> do
let qi = QualifiedIdentifier schema (cs proc)
exists <- doesProcExist schema proc
if exists
then do
row :: Maybe (Identity Text) <- H.maybeEx $ callProc qi $
fromMaybe M.empty (decode reqBody)
return $ responseLBS status200 [textH]
(cs $ fromMaybe "" $ runIdentity <$> row)
else return $ responseLBS status404 [] ""
-- check that proc exists
-- check that arg names are all specified
-- select * from "1".proc(a := "foo"::undefined) where whereT limit limitT
([table], "PUT") ->
handleJsonObj reqBody $ \obj -> do
let qt = qualify table
@@ -279,6 +294,9 @@ csvMT = "text/csv"
jsonH :: Header
jsonH = (hContentType, jsonMT)
textH :: Header
textH = (hContentType, "text/plain")
contentTypeForAccept :: Maybe BS.ByteString -> Maybe BS.ByteString
contentTypeForAccept accept
| isNothing accept || hasJson = Just jsonMT
@@ -295,7 +313,6 @@ bodyForAccept contentType table
| contentType == csvMT = asCsvWithCount table
| otherwise = asJsonWithCount -- defaults to JSON
handleJsonObj :: BL.ByteString -> (Object -> H.Tx P.Postgres s Response)
-> H.Tx P.Postgres s Response
handleJsonObj reqBody handler = do