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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package meta
6
7 import (
8 "appengine/datastore"
9
10 "infra/gae/libs/context"
11 "infra/libs/errors"
12 )
13
14 var mark = errors.MakeMarkFn("eg")
15
16 // EntityGroupMeta is the model corresponding to the __entity_group__ model in
17 // appengine. You shouldn't need to use this struct directly, but instead should
18 // use GetEntityGroupVersion.
19 type EntityGroupMeta struct {
20 _kind string `datastore:"-" goon:"kind,__entity_group__"`
21
22 ID int64 `datastore:"-" goon:"id"`
23 Parent *datastore.Key `datastore:"-" goon:"parent"`
24
25 Version int64 `datastore:"__version__"`
26 }
27
28 // GetEntityGroupVersion returns the entity group version for the entity group
29 // containing root. If the entity group doesn't exist, this function will return
30 // zero and a nil error.
31 func GetEntityGroupVersion(c context.SingleReadWriter, root *datastore.Key) (int 64, error) {
32 for root.Parent() != nil {
33 root = root.Parent()
34 }
35 egm := &EntityGroupMeta{ID: 1, Parent: root}
36 err := c.Get(egm)
37 if err != datastore.ErrNoSuchEntity {
38 err = mark(err)
39 } else {
40 // this is OK for callers. The version of the entity group is ef fectively 0
41 // in this case.
42 err = nil
43 }
44 return egm.Version, err
45 }
OLDNEW
« 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