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

Side by Side Diff: service/datastore/pls.go

Issue 1525453002: Handle unexpected entity fields gracefully. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix nit Created 5 years 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 | « service/datastore/datastore_test.go ('k') | service/datastore/pls_impl.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package datastore 5 package datastore
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "reflect" 9 "reflect"
10 ) 10 )
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // - Key 46 // - Key
47 // - int64 47 // - int64
48 // - string 48 // - string
49 // - Toggle (GetMeta and SetMeta treat the field as if it were bool) 49 // - Toggle (GetMeta and SetMeta treat the field as if it were bool)
50 // Additionally, int64, string and Toggle allow setting a default value 50 // Additionally, int64, string and Toggle allow setting a default value
51 // in the struct field tag (the "<value>" portion). 51 // in the struct field tag (the "<value>" portion).
52 // 52 //
53 // Only exported fields allow SetMeta, but all fields of appropriate type 53 // Only exported fields allow SetMeta, but all fields of appropriate type
54 // allow tagged defaults. See Examples. 54 // allow tagged defaults. See Examples.
55 // 55 //
56 // `gae:"[-],extra"` -- indicates that any extra, unrecognized or mismatched
57 // property types (type in datastore doesn't match your struct's field
58 // type) should be loaded into and saved from this field. The precise type
59 // of the field must be PropertyMap. This form allows you to control the
60 // behavior of reads and writes when your schema changes, or to implement
61 // something like ndb.Expando with a mix of structured and unstructured
62 // fields.
63 //
64 // If the `-` is present, then datastore write operations will not put
65 // elements of this map into the datastore.
66 //
67 // If the field is non-exported, then read operations from the datastore
68 // will not populate the members of this map, but extra fields or
69 // structural differences encountered when reading into this struct will be
70 // silently ignored. This is useful if you want to just ignore old fields.
71 //
72 // If there is a conflict between a field in the struct and a same-named
73 // Property in the extra field, the field in the struct takes precedence.
74 //
75 // Recursive structs are supported, but all extra properties go to the
76 // topmost structure's Extra field. This is a bit non-intuitive, but the
77 // implementation complexity was deemed not worth it, since that sort of
78 // thing is generally only useful on schema changes, which should be
79 // transient.
80 //
81 // Examples:
82 // // "black hole": ignore mismatches, ignore on write
83 // _ PropertyMap `gae:"-,extra"
84 //
85 // // "expando": full content is read/written
86 // Expando PropertyMap `gae:",extra"
87 //
88 // // "convert": content is read from datastore, but lost on writes. This
89 // // is useful for doing conversions from an old schema to a new one,
90 // // since you can retrieve the old data and populate it into new fields ,
91 // // for example. Probably should be used in conjunction with an
92 // // implementation of the PropertyLoadSaver interface so that you can
93 // // transparently upconvert to the new schema on load.
94 // Convert PropertyMap `gae:"-,extra"
95 //
56 // Example "special" structure. This is supposed to be some sort of datastore 96 // Example "special" structure. This is supposed to be some sort of datastore
57 // singleton object. 97 // singleton object.
58 // struct secretFoo { 98 // struct secretFoo {
59 // // _id and _kind are not exported, so setting their values will not be 99 // // _id and _kind are not exported, so setting their values will not be
60 // // reflected by GetMeta. 100 // // reflected by GetMeta.
61 // _id int64 `gae:"$id,1"` 101 // _id int64 `gae:"$id,1"`
62 // _kind string `gae:"$kind,InternalFooSingleton"` 102 // _kind string `gae:"$kind,InternalFooSingleton"`
63 // 103 //
64 // // Value is exported, so can be read and written by the PropertyLoadSaver , 104 // // Value is exported, so can be read and written by the PropertyLoadSaver ,
65 // // but secretFoo is shared with a python appengine module which has 105 // // but secretFoo is shared with a python appengine module which has
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if !ok { 228 if !ok {
189 structCodecsMutex.Lock() 229 structCodecsMutex.Lock()
190 defer structCodecsMutex.Unlock() 230 defer structCodecsMutex.Unlock()
191 c = getStructCodecLocked(structType) 231 c = getStructCodecLocked(structType)
192 } 232 }
193 if c.problem != nil { 233 if c.problem != nil {
194 panic(c.problem) 234 panic(c.problem)
195 } 235 }
196 return c 236 return c
197 } 237 }
OLDNEW
« no previous file with comments | « service/datastore/datastore_test.go ('k') | service/datastore/pls_impl.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698