googleapis / googleapis/google-cloud-go

datastore: Indication whether delete command was a no op or not

Open
#6,211 0 comments 0 reactions 1 assignee Assigned to @bhshkh View on GitHub
api: datastore next major: breaking change type: feature request
Dominant language
Go
Stars
4.5k
Forks
1.6k
Avg merge
1d 13h
Merged PRs (30d)
109

Description

**Is your feature request related to a problem? Please describe.**
When operating a delete command, it would be useful if there was a way to know if the command had an effect or if it was a no op (ie, the key being deleted didn't exist).

**Describe the solution you'd like**
Ideally `ErrKeyNotExists` or something like it would be returned, but that would be a breaking change. In the node client it appears there is a callback that gives you the ability to make a check by seeing the number of index updates that occured, ie:
```
function deleteOrThrow(keyOrKeys, cb) {
datastore.delete(keyOrKeys, function (err, res) {
if (!err && res.indexUpdates === 0) {
err = new Error('Nothing was deleted!');
}
cb(err, res);
});
}
```

**Describe alternatives you've considered**
I would need to do a get to verify the key exists before doing the delete. I would prefer to not do 2 roundtrips to datastore for a single delete.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.