OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package datastore | 5 package datastore |
6 | 6 |
7 import ( | 7 import ( |
8 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
9 ) | 9 ) |
10 | 10 |
11 // Interface is the 'user-friendly' interface to access the current filtered | 11 // Interface is the 'user-friendly' interface to access the current filtered |
12 // datastore service implementation. | 12 // datastore service implementation. |
13 // | 13 // |
14 // Note that in exchange for userfriendliness, this interface ends up doing | 14 // Note that in exchange for userfriendliness, this interface ends up doing |
15 // a lot of reflection. | 15 // a lot of reflection. |
16 // | 16 // |
17 // Methods taking 'interface{}' objects describe what a valid type for that | 17 // Methods taking 'interface{}' objects describe what a valid type for that |
18 // interface are in the comments. | 18 // interface are in the comments. |
19 // | 19 // |
20 // Struct objects passed in will be converted to PropertyLoadSaver interfaces | 20 // Struct objects passed in will be converted to PropertyLoadSaver interfaces |
21 // using this package's GetPLS function. | 21 // using this package's GetPLS function. |
22 type Interface interface { | 22 type Interface interface { |
23 // AllocateIDs allows you to allocate IDs from the datastore without put
ting | 23 // AllocateIDs allows you to allocate IDs from the datastore without put
ting |
24 » // any data. `incomplete` must be a PartialValid Key. If there's no erro
r, | 24 » // any data. |
25 » // a contiguous block of IDs of n length starting at `start` will be res
erved | 25 » // |
26 » // indefinitely for the user application code for use in new keys. The | 26 » // A partial valid key will be constructed from each entity's kind and p
arent, |
27 » // appengine automatic ID generator will never automatically assign thes
e IDs | 27 » // if present. An allocation will then be performed against the datastor
e for |
28 » // for Keys of this type. | 28 » // each key, and the partial key will be populated with a unique integer
ID. |
29 » AllocateIDs(incomplete *Key, n int) (start int64, err error) | 29 » // The resulting keys will be applied to their objects using PopulateKey
. If |
| 30 » // successful, any existing ID will be destroyed. |
| 31 » // |
| 32 » // If the object is supplied that cannot accept an integer key, this met
hod |
| 33 » // will panic. |
| 34 » // |
| 35 » // ent must be one of: |
| 36 » //» - *S where S is a struct |
| 37 » //» - *P where *P is a concrete type implementing PropertyLoadSaver |
| 38 » //» - []S or []*S where S is a struct |
| 39 » //» - []P or []*P where *P is a concrete type implementing PropertyL
oadSaver |
| 40 » //» - []I where i is some interface type. Each element of the slice
must |
| 41 » //» be non-nil, and its underlying type must be either *S or *P. |
| 42 » //» - []*Key, to populate a slice of partial-valid keys. |
| 43 » // |
| 44 » // If an error is encountered, the returned error value will depend on t
he |
| 45 » // input arguments. If one argument is supplied, the result will be the |
| 46 » // encountered error type. If multiple arguments are supplied, the resul
t will |
| 47 » // be a MultiError whose error index corresponds to the argument in whic
h the |
| 48 » // error was encountered. |
| 49 » // |
| 50 » // If an ent argument is a slice, its error type will be a MultiError. N
ote |
| 51 » // that in the scenario where multiple slices are provided, this will re
turn a |
| 52 » // MultiError containing a nested MultiError for each slice argument. |
| 53 » AllocateIDs(ent ...interface{}) error |
30 | 54 |
31 // KeyForObj extracts a key from src. | 55 // KeyForObj extracts a key from src. |
32 // | 56 // |
33 // It is the same as KeyForObjErr, except that if KeyForObjErr would hav
e | 57 // It is the same as KeyForObjErr, except that if KeyForObjErr would hav
e |
34 // returned an error, this method panics. It's safe to use if you know t
hat | 58 // returned an error, this method panics. It's safe to use if you know t
hat |
35 // src statically meets the metadata constraints described by KeyForObjE
rr. | 59 // src statically meets the metadata constraints described by KeyForObjE
rr. |
36 KeyForObj(src interface{}) *Key | 60 KeyForObj(src interface{}) *Key |
37 | 61 |
38 // MakeKey is a convenience method for manufacturing a *Key. It should o
nly be | 62 // MakeKey is a convenience method for manufacturing a *Key. It should o
nly be |
39 // used when elems... is known statically (e.g. in the code) to be corre
ct. | 63 // used when elems... is known statically (e.g. in the code) to be corre
ct. |
40 // | 64 // |
41 // elems is pairs of (string, string|int|int32|int64) pairs, which corre
spond | 65 // elems is pairs of (string, string|int|int32|int64) pairs, which corre
spond |
42 // to Kind/id pairs. Example: | 66 // to Kind/id pairs. Example: |
43 // dstore.MakeKey("Parent", 1, "Child", "id") | 67 // dstore.MakeKey("Parent", 1, "Child", "id") |
44 // | 68 // |
45 // Would create the key: | 69 // Would create the key: |
46 // <current appID>:<current Namespace>:/Parent,1/Child,id | 70 // <current appID>:<current Namespace>:/Parent,1/Child,id |
47 // | 71 // |
48 // If elems is not parsable (e.g. wrong length, wrong types, etc.) this
method | 72 // If elems is not parsable (e.g. wrong length, wrong types, etc.) this
method |
49 // will panic. | 73 // will panic. |
50 MakeKey(elems ...interface{}) *Key | 74 MakeKey(elems ...interface{}) *Key |
51 | 75 |
52 // NewKey constructs a new key in the current appID/Namespace, using the | 76 // NewKey constructs a new key in the current appID/Namespace, using the |
53 // specified parameters. | 77 // specified parameters. |
54 NewKey(kind, stringID string, intID int64, parent *Key) *Key | 78 NewKey(kind, stringID string, intID int64, parent *Key) *Key |
55 | 79 |
| 80 // NewIncompleteKeys allocates count incomplete keys sharing the same ki
nd and |
| 81 // parent. It is useful as input to AllocateIDs. |
| 82 NewIncompleteKeys(count int, kind string, parent *Key) []*Key |
| 83 |
56 // NewKeyToks constructs a new key in the current appID/Namespace, using
the | 84 // NewKeyToks constructs a new key in the current appID/Namespace, using
the |
57 // specified key tokens. | 85 // specified key tokens. |
58 NewKeyToks([]KeyTok) *Key | 86 NewKeyToks([]KeyTok) *Key |
59 | 87 |
60 // KeyForObjErr extracts a key from src. | 88 // KeyForObjErr extracts a key from src. |
61 // | 89 // |
62 // src must be one of: | 90 // src must be one of: |
63 // - *S, where S is a struct | 91 // - *S, where S is a struct |
64 // - a PropertyLoadSaver | 92 // - a PropertyLoadSaver |
65 // | 93 // |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // - []S or []*S, where S is a struct | 225 // - []S or []*S, where S is a struct |
198 // - []P or []*P, where *P is a concrete type implementing PropertyLoa
dSaver | 226 // - []P or []*P, where *P is a concrete type implementing PropertyLoa
dSaver |
199 // - []I, where I is some interface type. Each element of the slice mu
st | 227 // - []I, where I is some interface type. Each element of the slice mu
st |
200 // be non-nil, and its underlying type must be either *S or *P. | 228 // be non-nil, and its underlying type must be either *S or *P. |
201 // | 229 // |
202 // NOTE: GetMulti is obsolete. The vararg-accepting Get should be used | 230 // NOTE: GetMulti is obsolete. The vararg-accepting Get should be used |
203 // instead. This is left for backwards compatibility, but will be remove
d from | 231 // instead. This is left for backwards compatibility, but will be remove
d from |
204 // this interface at some point in the future. | 232 // this interface at some point in the future. |
205 GetMulti(dst interface{}) error | 233 GetMulti(dst interface{}) error |
206 | 234 |
207 » // Put inserts a single object into the datastore | 235 » // Put writes objects into the datastore. |
208 // | 236 // |
209 // src must be one of: | 237 // src must be one of: |
210 // - *S, where S is a struct | 238 // - *S, where S is a struct |
211 // - *P, where *P is a concrete type implementing PropertyLoadSaver | 239 // - *P, where *P is a concrete type implementing PropertyLoadSaver |
212 // - []S or []*S, where S is a struct | 240 // - []S or []*S, where S is a struct |
213 // - []P or []*P, where *P is a concrete type implementing Property
LoadSaver | 241 // - []P or []*P, where *P is a concrete type implementing Property
LoadSaver |
214 // - []I, where I is some interface type. Each element of the slice
must | 242 // - []I, where I is some interface type. Each element of the slice
must |
215 // be non-nil, and its underlying type must be either *S or *P. | 243 // be non-nil, and its underlying type must be either *S or *P. |
216 // | 244 // |
217 // A *Key will be extracted from src via KeyForObj. If | 245 // A *Key will be extracted from src via KeyForObj. If |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 308 |
281 // Testable returns the Testable interface for the implementation, or ni
l if | 309 // Testable returns the Testable interface for the implementation, or ni
l if |
282 // there is none. | 310 // there is none. |
283 Testable() Testable | 311 Testable() Testable |
284 | 312 |
285 // Raw returns the underlying RawInterface. The Interface and RawInterfa
ce may | 313 // Raw returns the underlying RawInterface. The Interface and RawInterfa
ce may |
286 // be used interchangably; there's no danger of interleaving access to t
he | 314 // be used interchangably; there's no danger of interleaving access to t
he |
287 // datastore via the two. | 315 // datastore via the two. |
288 Raw() RawInterface | 316 Raw() RawInterface |
289 } | 317 } |
OLD | NEW |