All green

But still unsightly
This commit is contained in:
Joe Nelson
2015-11-22 22:38:54 -08:00
parent bc552848ba
commit 7f58600dbb
2 changed files with 16 additions and 51 deletions
+15 -11
View File
@@ -241,17 +241,21 @@ requestToQuery schema (Node (Insert _ (PayloadJSON (UniformObjects rows)), (main
" FROM json_populate_recordset(null::" , fromQi qi, ", ?)",
" RETURNING " <> fromQi qi <> ".*"
]
-- requestToQuery schema (Node (Update _ setWith conditions, (mainTbl, _)) _) =
-- query
-- where
-- qi = QualifiedIdentifier schema mainTbl
-- query = unwords [
-- "UPDATE ", fromQi qi,
-- " SET " <> intercalate ", " (map formatSet (M.toList setWith)) <> " ",
-- ("WHERE " <> intercalate " AND " ( map (pgFmtCondition qi ) conditions )) `emptyOnNull` conditions,
-- "RETURNING " <> fromQi qi <> ".*"
-- ]
-- formatSet ((c, jp), v) = pgFmtIdent c <> pgFmtJsonPath jp <> " = " <> insertableValue v
requestToQuery schema (Node (Update _ (PayloadJSON (UniformObjects rows)) conditions, (mainTbl, _)) _) =
case rows V.!? 0 of
Just obj ->
let assignments = map
(\(k,v) -> pgFmtIdent k <> "=" <> insertableValue v) $ HM.toList obj in
unwords [
"UPDATE ", fromQi qi,
" SET " <> (intercalate "," assignments) <> " ",
("WHERE " <> intercalate " AND " ( map (pgFmtCondition qi ) conditions )) `emptyOnNull` conditions,
"RETURNING " <> fromQi qi <> ".*"
]
Nothing -> ""
where
qi = QualifiedIdentifier schema mainTbl
requestToQuery schema (Node (Delete _ conditions, (mainTbl, _)) _) =
query
where