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

Unified Diff: service/datastore/meta/eg.go

Issue 1917513002: Add meta package to datastore. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 8 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
Index: service/datastore/meta/eg.go
diff --git a/service/datastore/meta/eg.go b/service/datastore/meta/eg.go
new file mode 100644
index 0000000000000000000000000000000000000000..11c31024473e7ef84f8d816e72a1727a0e3e5a3b
--- /dev/null
+++ b/service/datastore/meta/eg.go
@@ -0,0 +1,37 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package meta
+
+import (
+ "github.com/luci/gae/service/datastore"
+ "golang.org/x/net/context"
+)
+
+// EntityGroupMeta is the model corresponding to the __entity_group__ model in
+// appengine. You shouldn't need to use this struct directly, but instead should
+// use GetEntityGroupVersion.
+type EntityGroupMeta struct {
dnj 2016/04/23 02:17:10 (This is verbatim transplant from luci-go)
+ kind string `gae:"$kind,__entity_group__"`
+ id int64 `gae:"$id,1"`
+ Parent *datastore.Key `gae:"$parent"`
+
+ Version int64 `gae:"__version__"`
+}
+
+// GetEntityGroupVersion returns the entity group version for the entity group
+// containing root. If the entity group doesn't exist, this function will return
+// zero and a nil error.
+func GetEntityGroupVersion(c context.Context, key *datastore.Key) (int64, error) {
+ ds := datastore.Get(c)
+ egm := &EntityGroupMeta{Parent: key.Root()}
+ err := ds.Get(egm)
+ ret := egm.Version
+ if err == datastore.ErrNoSuchEntity {
+ // this is OK for callers. The version of the entity group is effectively 0
+ // in this case.
+ err = nil
+ }
+ return ret, err
+}

Powered by Google App Engine
This is Rietveld 408576698