Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Cpp/fostgres/response.csj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,28 @@ namespace {
error = handler.update(linedata, records);
break;
}
if (error.first) return error;
if (error.first) {
return error;
} else if (error.second) {
switch (error.second) {
case 404:
return fostlib::urlhandler::view::execute(
fostlib::json{"fost.response.404"}, "", req,
fostlib::host{});
default:
throw fostlib::exceptions::not_implemented(
__PRETTY_FUNCTION__,
"Canned response for this status code",
fostlib::coerce<fostlib::string>(error.second));
}
}
++records;
}
cnx.commit();
fostlib::insert(work_done, "records", records);
boost::shared_ptr<fostlib::mime> response(new fostlib::text_body(
fostlib::json::unparse(work_done, true),
fostlib::mime::mime_headers(), L"application/json"));
fostlib::mime::mime_headers(), "application/json"));
return std::make_pair(response, 200);
}

Expand Down
11 changes: 10 additions & 1 deletion Cpp/fostgres/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,16 @@ std::pair<boost::shared_ptr<fostlib::mime>, int> fostgres::updater::update(
fostgres::updater::intermediate_data d,
std::optional<std::size_t> row) {
auto rel = relation;
cnx.update(rel.shrink_to_fit(), d.first, d.second);
std::vector<fostlib::string> returning = {"*"};
auto rs = cnx.update(rel.shrink_to_fit(), d.first, d.second, returning);
auto pos = rs.begin();
if (pos == rs.end()) {
return {nullptr, 404};
} else if (++pos != rs.end()) {
throw fostlib::exceptions::not_implemented(
__PRETTY_FUNCTION__,
"Update for multiple rows not supported by Fostgres");
}
return {nullptr, 0};
}

Expand Down
2 changes: 1 addition & 1 deletion Example/films/films.fg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## `UPDATE` statements instead of `INSERT` ones. If these don't actually
## update anything then we will get a 404 back, denoting that the
## resource we're trying to update doesn't exist.
#PATCH film.slug.error / (module.path.join films.edit.csj) 404
PATCH film.slug.error / (module.path.join films.edit.csj) 404


## ## Add films normally
Expand Down