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

Unified Diff: go/src/infra/gae/libs/meta/eg.go

Issue 985583003: Thin library for interacting with the GAE datastore metadata entities. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@context
Patch Set: Disable tests since they would simply test that dev_appserver correctly mocks the real metadata obj… Created 5 years, 9 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 | go/src/infra/gae/libs/meta/meta.infra_testing » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/meta/eg.go
diff --git a/go/src/infra/gae/libs/meta/eg.go b/go/src/infra/gae/libs/meta/eg.go
new file mode 100644
index 0000000000000000000000000000000000000000..55ddce438685cff033561bdfbf30c12ccda0331c
--- /dev/null
+++ b/go/src/infra/gae/libs/meta/eg.go
@@ -0,0 +1,45 @@
+// 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 (
+ "appengine/datastore"
+
+ "infra/gae/libs/context"
+ "infra/libs/errors"
+)
+
+var mark = errors.MakeMarkFn("eg")
+
+// 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 {
+ _kind string `datastore:"-" goon:"kind,__entity_group__"`
+
+ ID int64 `datastore:"-" goon:"id"`
+ Parent *datastore.Key `datastore:"-" goon:"parent"`
+
+ Version int64 `datastore:"__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.SingleReadWriter, root *datastore.Key) (int64, error) {
+ for root.Parent() != nil {
+ root = root.Parent()
+ }
+ egm := &EntityGroupMeta{ID: 1, Parent: root}
+ err := c.Get(egm)
+ if err != datastore.ErrNoSuchEntity {
+ err = mark(err)
+ } else {
+ // this is OK for callers. The version of the entity group is effectively 0
+ // in this case.
+ err = nil
+ }
+ return egm.Version, err
+}
« no previous file with comments | « no previous file | go/src/infra/gae/libs/meta/meta.infra_testing » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698