Chromium Code Reviews

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: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « no previous file | no next file » | 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)
Vadim Sh. 2015/03/06 03:01:48 nit: 'mark' is too general. It is ok in such small
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 | no next file » | no next file with comments »

Powered by Google App Engine