Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Unified Diff: service/datastore/datastore.go

Issue 1398103003: Add Exists and ExistsMulti convenience methods (Closed) Base URL: https://github.com/luci/gae.git@add_version_id
Patch Set: comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | service/datastore/datastore_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/datastore.go
diff --git a/service/datastore/datastore.go b/service/datastore/datastore.go
index 3db1919f3fc58a246e1216515b4076d6f58a38c6..6ded9554dbc2d809f932341baf424113e6a400b6 100644
--- a/service/datastore/datastore.go
+++ b/service/datastore/datastore.go
@@ -182,6 +182,29 @@ func isOkType(v reflect.Type) bool {
return false
}
+func (d *datastoreImpl) ExistsMulti(keys []*Key) ([]bool, error) {
+ lme := errors.NewLazyMultiError(len(keys))
+ ret := make([]bool, len(keys))
+ i := 0
+ err := d.RawInterface.GetMulti(keys, nil, func(_ PropertyMap, err error) {
+ if err == nil {
+ ret[i] = true
+ } else if err != ErrNoSuchEntity {
+ lme.Assign(i, err)
+ }
+ i++
+ })
+ if err != nil {
+ return ret, err
+ }
+ return ret, lme.Get()
+}
+
+func (d *datastoreImpl) Exists(k *Key) (bool, error) {
+ ret, err := d.ExistsMulti([]*Key{k})
+ return ret[0], errors.SingleError(err)
+}
+
func (d *datastoreImpl) Get(dst interface{}) (err error) {
if !isOkType(reflect.TypeOf(dst)) {
return fmt.Errorf("invalid Get input type: %T", dst)
« no previous file with comments | « no previous file | service/datastore/datastore_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698