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

Unified Diff: service/datastore/datastore.go

Issue 1867963003: Add PopulateKey method 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pre-commit-go.yml ('k') | service/datastore/datastore_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/datastore.go
diff --git a/service/datastore/datastore.go b/service/datastore/datastore.go
index 17305e57901d7eb5e996175a3c524d5531fde2d2..752c99c55779e02a2f97cced14b351645f18a6af 100644
--- a/service/datastore/datastore.go
+++ b/service/datastore/datastore.go
@@ -52,6 +52,26 @@ func (d *datastoreImpl) NewKeyToks(toks []KeyTok) *Key {
return NewKeyToks(d.aid, d.ns, toks)
}
+// PopulateKey loads key into obj.
+//
+// obj is any object that Interface.Get is able to accept.
+//
+// This method will panic if obj is an invalid datastore model. If the key could
+// not be applied to the object, nothing will happen.
+func PopulateKey(obj interface{}, key *Key) {
+ pls := getMGS(obj)
+ if !pls.SetMeta("key", key) {
+ lst := key.LastTok()
+ if lst.StringID != "" {
+ pls.SetMeta("id", lst.StringID)
+ } else {
+ pls.SetMeta("id", lst.IntID)
+ }
+ pls.SetMeta("kind", lst.Kind)
+ pls.SetMeta("parent", key.Parent())
+ }
+}
+
func runParseCallback(cbIface interface{}) (isKey, hasErr, hasCursorCB bool, mat multiArgType) {
badSig := func() {
panic(fmt.Errorf(
« no previous file with comments | « pre-commit-go.yml ('k') | service/datastore/datastore_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698