google-cloud-cpp
google-cloud-cpp copied to clipboard
Support `std::function<Status(Transaction)>` in `Commit()`
The spanner::Client::Commit()
function consumes a std::function<StatusOr<Mutations>(Transaction)> mutator
parameter:
https://github.com/googleapis/google-cloud-cpp/blob/e84a574ad5c761a4cc771a9b1f1102077fb6ec66/google/cloud/spanner/client.h#L749-L750
Applications using just SQL statements may wonder why they need to return an empty set of spanner::Mutations
from the Commit()
mutator. If they had no intention of using Mutations
they could just return Status{}
on success.
Nice to have, not urgent. Let's plan for 2022-Q4
If they had no intention of using
Mutations
they could just returnStatus{}
on success.
You can't assign an OK Status
to a StatusOr<T>
. So, the logical way forward here would be to introduce a new Client::Commit()
overload ...
StatusOr<CommitResult> Commit(
std::function<Status(Transaction)> const& mutator, Options opts = {});
which could then be called with something like ...
auto commit =
client.Commit([&](google::cloud::spanner::Transaction const& txn) {
auto result = client.Op(txn, ...);
if (!result) return std::move(result).status();
// ... etc
return google::cloud::Status{};
});
Unfortunately such a call is ambiguous with the existing
StatusOr<CommitResult> Commit(
std::function<StatusOr<Mutations>(Transaction)> const& mutator,
Options opts = {});
overload, so something more complicated would be required, which kind of defeats the purpose.
Applications using just SQL statements may wonder why they need to return an empty set of
spanner::Mutations
from theCommit()
mutator.
I'm not sure why they need wonder too much, or be confused by it. They're just saying that there are no additional mutations.
Applications using just SQL statements may wonder why they need to return an empty set of
spanner::Mutations
from theCommit()
mutator.I'm not sure why they need wonder too much, or be confused by it. They're just saying that there are no additional mutations.
People should only learn as many new concepts as needed to use the library. It seems unfortunate that to use the SQL interface I would need to learn about the spanner::Mutations
too, even if I do not plan to use them.
After some thought, we don't think this is needed.