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

Side by Side 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 unified diff | Download patch
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 "github.com/luci/gae/service/datastore"
9 "golang.org/x/net/context"
10 )
11
12 // EntityGroupMeta is the model corresponding to the __entity_group__ model in
13 // appengine. You shouldn't need to use this struct directly, but instead should
14 // use GetEntityGroupVersion.
15 type EntityGroupMeta struct {
dnj 2016/04/23 02:17:10 (This is verbatim transplant from luci-go)
16 kind string `gae:"$kind,__entity_group__"`
17 id int64 `gae:"$id,1"`
18 Parent *datastore.Key `gae:"$parent"`
19
20 Version int64 `gae:"__version__"`
21 }
22
23 // GetEntityGroupVersion returns the entity group version for the entity group
24 // containing root. If the entity group doesn't exist, this function will return
25 // zero and a nil error.
26 func GetEntityGroupVersion(c context.Context, key *datastore.Key) (int64, error) {
27 ds := datastore.Get(c)
28 egm := &EntityGroupMeta{Parent: key.Root()}
29 err := ds.Get(egm)
30 ret := egm.Version
31 if err == datastore.ErrNoSuchEntity {
32 // this is OK for callers. The version of the entity group is ef fectively 0
33 // in this case.
34 err = nil
35 }
36 return ret, err
37 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698