Add PUT handler

This commit is contained in:
Joe Nelson
2014-12-06 17:42:17 -08:00
parent 8894400f5c
commit 361cffc283
2 changed files with 44 additions and 38 deletions
+18
View File
@@ -61,6 +61,13 @@ parentheticT :: CompleteQueryT
parentheticT (sql, params) =
(" (" <> sql <> ") ", params)
aIffNotBT :: CompleteQuery -> CompleteQueryT
aIffNotBT (aq, ap) (bq, bp) =
("WITH aaa AS (" <> aq <> " returning *) " <>
bq <> "WHERE NOT EXISTS (SELECT * FROM aaa)"
, ap ++ bp
)
countRows :: QualifiedTable -> CompleteQuery
countRows t =
("select count(1) from ?.?",
@@ -92,6 +99,17 @@ insertInto t cols vals =
++ map EscapeIdentifier cols ++ map toField vals
)
update :: QualifiedTable -> [BS.ByteString] -> [Value] ->
CompleteQuery
update t cols vals =
("update ?.? set (" <>
Query (BS.intercalate ", " (map (const "?") cols)) <>
") = (" <>
Query (BS.intercalate ", " (map (const "?") vals)) <> ")"
, [EscapeIdentifier (qtSchema t), EscapeIdentifier (qtName t)]
++ map EscapeIdentifier cols ++ map toField vals
)
wherePred :: Net.QueryItem -> CompleteQuery
wherePred (col, predicate) =
(" ? ? ? ", [EscapeIdentifier col, Plain op, toField value])