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 |
+} |