OLD | NEW |
---|---|
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 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
9 ) | 9 ) |
10 | 10 |
11 // BoolList is a convenience wrapper for []bool that provides summary methods | |
12 // for working with the list in aggregate. | |
13 type BoolList []bool | |
14 | |
15 // All returns true iff all of the booleans in this list are true. | |
16 func (bl BoolList) All() bool { | |
17 for _, b := range bl { | |
18 if !b { | |
19 return false | |
20 } | |
21 } | |
22 return true | |
23 } | |
24 | |
25 // Any returns true iff any of the booleans in this list are true. | |
26 func (bl BoolList) Any() bool { | |
27 for _, b := range bl { | |
28 if b { | |
29 return true | |
30 } | |
31 } | |
32 return false | |
33 } | |
34 | |
35 // Interface is the 'user-friendly' interface to access the current filtered | 11 // Interface is the 'user-friendly' interface to access the current filtered |
36 // datastore service implementation. | 12 // datastore service implementation. |
37 // | 13 // |
38 // Note that in exchange for userfriendliness, this interface ends up doing | 14 // Note that in exchange for userfriendliness, this interface ends up doing |
39 // a lot of reflection. | 15 // a lot of reflection. |
40 // | 16 // |
41 // Methods taking 'interface{}' objects describe what a valid type for that | 17 // Methods taking 'interface{}' objects describe what a valid type for that |
42 // interface are in the comments. | 18 // interface are in the comments. |
43 // | 19 // |
44 // Struct objects passed in will be converted to PropertyLoadSaver interfaces | 20 // Struct objects passed in will be converted to PropertyLoadSaver interfaces |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 | 127 |
152 // GetAll retrieves all of the Query results into dst. | 128 // GetAll retrieves all of the Query results into dst. |
153 // | 129 // |
154 // dst must be one of: | 130 // dst must be one of: |
155 // - *[]S or *[]*S where S is a struct | 131 // - *[]S or *[]*S where S is a struct |
156 // - *[]P or *[]*P where *P is a concrete type implementing | 132 // - *[]P or *[]*P where *P is a concrete type implementing |
157 // PropertyLoadSaver | 133 // PropertyLoadSaver |
158 // - *[]*Key implies a keys-only query. | 134 // - *[]*Key implies a keys-only query. |
159 GetAll(q *Query, dst interface{}) error | 135 GetAll(q *Query, dst interface{}) error |
160 | 136 |
161 » // Does a Get for this key and returns true iff it exists. Will only ret urn | 137 » // Exists tests if the supplied objects are present in the datastore. |
162 » // an error if it's not ErrNoSuchEntity. This is slightly more efficient | 138 » // |
163 » // than using Get directly, because it uses the underlying RawInterface to | 139 » // ent must be one of: |
164 » // avoid some reflection and copies. | 140 » //» - *S where S is a struct |
165 » Exists(k *Key) (bool, error) | 141 » //» - *P where *P is a concrete type implementing PropertyLoadSaver |
142 » //» - []S or []*S where S is a struct | |
143 » //» - []P or []*P where *P is a concrete type implementing PropertyL oadSaver | |
144 » //» - []I where i is some interface type. Each elemet of the slice m ust | |
iannucci
2016/05/28 02:50:53
elemet!
dnj
2016/05/28 17:47:21
Done.
| |
145 » //» be non-nil, and its underlying type must be either *S or *P. | |
146 » //» - *Key, to check a specific key from the datastore. | |
147 » //» - []*Key, to check a slice of keys from the datastore. | |
148 » // | |
149 » // If an error is encountered, the returned error value will depend on t he | |
150 » // input arguments. If one argument is supplied, the result will be the | |
151 » // encountered error type. If multiple arguments are supplied, the resul t will | |
152 » // be a MultiError whose error index corresponds to the argument in whic h the | |
153 » // error was encountered. | |
154 » // | |
155 » // If an ent argument is a slice, its error type will be a MultiError. N ote | |
156 » // that in the scenario where multiple slices are provided, this will re turn a | |
157 » // return a MultiError containing a nexted MultiError for each slice arg ument. | |
iannucci
2016/05/28 02:50:53
return a return a
nexted
dnj
2016/05/28 17:47:21
Done.
| |
158 » Exists(ent ...interface{}) (*ExistsResult, error) | |
166 | 159 |
167 // Does a GetMulti for thes keys and returns true iff they exist. Will o nly | 160 // Does a GetMulti for thes keys and returns true iff they exist. Will o nly |
168 // return an error if it's not ErrNoSuchEntity. This is slightly more ef ficient | 161 // return an error if it's not ErrNoSuchEntity. This is slightly more ef ficient |
169 // than using Get directly, because it uses the underlying RawInterface to | 162 // than using Get directly, because it uses the underlying RawInterface to |
170 // avoid some reflection and copies. | 163 // avoid some reflection and copies. |
164 // | |
165 // If an error is encountered, the returned error will be a MultiError w hose | |
166 // error index corresponds to the key for which the error was encountere d. | |
167 // | |
168 // NOTE: ExistsMulti is obsolete. The vararg-accepting Exists should be used | |
169 // instead. This is left for backwards compatibility, but will be remove d from | |
170 // this interface at some point in the future. | |
171 ExistsMulti(k []*Key) (BoolList, error) | 171 ExistsMulti(k []*Key) (BoolList, error) |
172 | 172 |
173 » // Get retrieves a single object from the datastore | 173 » // Get retrieves objects from the datastore. |
174 // | 174 // |
175 » // dst must be one of: | 175 » // Each element in dst must be one of: |
176 » // - *S where S is a struct | 176 » //» - *S where S is a struct |
177 » // - *P where *P is a concrete type implementing PropertyLoadSaver | 177 » //» - *P where *P is a concrete type implementing PropertyLoadSaver |
178 » Get(dst interface{}) error | 178 » //» - []S or []*S where S is a struct |
179 | 179 » //» - []P or []*P where *P is a concrete type implementing PropertyL oadSaver |
180 » // Put inserts a single object into the datastore | 180 » //» - []I where I is some interface type. Each element of the slice must |
181 » //» be non-nil, and its underlying type must be either *S or *P. | |
181 // | 182 // |
182 » // src must be one of: | 183 » // If an error is encountered, the returned error value will depend on t he |
183 » // - *S where S is a struct | 184 » // input arguments. If one argument is supplied, the result will be the |
184 » // - *P where *P is a concrete type implementing PropertyLoadSaver | 185 » // encountered error type. If multiple arguments are supplied, the resul t will |
186 » // be a MultiError whose error index corresponds to the argument in whic h the | |
187 » // error was encountered. | |
185 // | 188 // |
186 » // A *Key will be extracted from src via KeyForObj. If | 189 » // If a dst argument is a slice, its error type will be a MultiError. No te |
187 » // extractedKey.Incomplete() is true, then Put will write the resolved ( i.e. | 190 » // that in the scenario where multiple slices are provided, this will re turn a |
188 » // automatic datastore-populated) *Key back to src. | 191 » // return a MultiError containing a nexted MultiError for each slice arg ument. |
189 » Put(src interface{}) error | 192 » Get(dst ...interface{}) error |
190 | |
191 » // Delete removes an item from the datastore. | |
192 » Delete(key *Key) error | |
193 | 193 |
194 // GetMulti retrieves items from the datastore. | 194 // GetMulti retrieves items from the datastore. |
195 // | 195 // |
196 // dst must be one of: | 196 // dst must be one of: |
197 // - []S or []*S where S is a struct | 197 // - []S or []*S where S is a struct |
198 // - []P or []*P where *P is a concrete type implementing PropertyLoad Saver | 198 // - []P or []*P where *P is a concrete type implementing PropertyLoad Saver |
199 // - []I where I is some interface type. Each element of the slice mus t | 199 // - []I where I is some interface type. Each element of the slice mus t |
200 // be non-nil, and its underlying type must be either *S or *P. | 200 // be non-nil, and its underlying type must be either *S or *P. |
201 // | |
202 // 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 | |
204 // this interface at some point in the future. | |
201 GetMulti(dst interface{}) error | 205 GetMulti(dst interface{}) error |
202 | 206 |
207 // Put inserts a single object into the datastore | |
208 // | |
209 // src must be one of: | |
210 // - *S where S is a struct | |
211 // - *P where *P is a concrete type implementing PropertyLoadSaver | |
212 // - []S or []*S where S is a struct | |
213 // - []P or []*P where *P is a concrete type implementing PropertyL oadSaver | |
214 // - []I where i is some interface type. Each elemet of the slice m ust | |
215 // be non-nil, and its underlying type must be either *S or *P. | |
216 // | |
217 // A *Key will be extracted from src via KeyForObj. If | |
218 // extractedKey.Incomplete() is true, then Put will write the resolved ( i.e. | |
219 // automatic datastore-populated) *Key back to src. | |
220 // | |
221 // If an error is encountered, the returned error value will depend on t he | |
222 // input arguments. If one argument is supplied, the result will be the | |
223 // encountered error type. If multiple arguments are supplied, the resul t will | |
224 // be a MultiError whose error index corresponds to the argument in whic h the | |
225 // error was encountered. | |
226 // | |
227 // If a src argument is a slice, its error type will be a MultiError. No te | |
228 // that in the scenario where multiple slices are provided, this will re turn a | |
229 // return a MultiError containing a nexted MultiError for each slice arg ument. | |
230 Put(src ...interface{}) error | |
231 | |
203 // PutMulti writes items to the datastore. | 232 // PutMulti writes items to the datastore. |
204 // | 233 // |
205 // src must be one of: | 234 // src must be one of: |
206 » // - []S or []*S where S is a struct | 235 » //» - []S or []*S where S is a struct |
207 » // - []P or []*P where *P is a concrete type implementing PropertyLoad Saver | 236 » //» - []P or []*P where *P is a concrete type implementing PropertyL oadSaver |
208 » // - []I where i is some interface type. Each elemet of the slice must | 237 » //» - []I where i is some interface type. Each elemet of the slice m ust |
209 » // be non-nil, and its underlying type must be either *S or *P. | 238 » //» be non-nil, and its underlying type must be either *S or *P. |
210 // | 239 // |
211 // If items in src resolve to Incomplete keys, PutMulti will write the | 240 // If items in src resolve to Incomplete keys, PutMulti will write the |
212 // resolved keys back to the items in src. | 241 // resolved keys back to the items in src. |
242 // | |
243 // NOTE: PutMulti is obsolete. The vararg-accepting Put should be used | |
244 // instead. This is left for backwards compatibility, but will be remove d from | |
245 // this interface at some point in the future. | |
213 PutMulti(src interface{}) error | 246 PutMulti(src interface{}) error |
214 | 247 |
215 » // DeleteMulti removes items from the datastore. | 248 » // Delete removes the supplied entities from the datastore. |
249 » // | |
250 » // ent must be one of: | |
251 » //» - *S where S is a struct | |
252 » //» - *P where *P is a concrete type implementing PropertyLoadSaver | |
253 » //» - []S or []*S where S is a struct | |
254 » //» - []P or []*P where *P is a concrete type implementing PropertyL oadSaver | |
255 » //» - []I where i is some interface type. Each elemet of the slice m ust | |
256 » //» be non-nil, and its underlying type must be either *S or *P. | |
257 » //» - *Key, to remove a specific key from the datastore. | |
258 » //» - []*Key, to remove a slice of keys from the datastore. | |
259 » // | |
260 » // If an error is encountered, the returned error value will depend on t he | |
261 » // input arguments. If one argument is supplied, the result will be the | |
262 » // encountered error type. If multiple arguments are supplied, the resul t will | |
263 » // be a MultiError whose error index corresponds to the argument in whic h the | |
264 » // error was encountered. | |
265 » // | |
266 » // If an ent argument is a slice, its error type will be a MultiError. N ote | |
267 » // that in the scenario where multiple slices are provided, this will re turn a | |
268 » // return a MultiError containing a nexted MultiError for each slice arg ument. | |
269 » Delete(ent ...interface{}) error | |
270 | |
271 » // DeleteMulti removes keys from the datastore. | |
272 » // | |
273 » // If an error is encountered, the returned error will be a MultiError w hose | |
274 » // error index corresponds to the key for which the error was encountere d. | |
275 » // | |
276 » // NOTE: DeleteMulti is obsolete. The vararg-accepting Delete should be used | |
277 » // instead. This is left for backwards compatibility, but will be remove d from | |
278 » // this interface at some point in the future. | |
216 DeleteMulti(keys []*Key) error | 279 DeleteMulti(keys []*Key) error |
217 | 280 |
218 // Testable returns the Testable interface for the implementation, or ni l if | 281 // Testable returns the Testable interface for the implementation, or ni l if |
219 // there is none. | 282 // there is none. |
220 Testable() Testable | 283 Testable() Testable |
221 | 284 |
222 // Raw returns the underlying RawInterface. The Interface and RawInterfa ce may | 285 // Raw returns the underlying RawInterface. The Interface and RawInterfa ce may |
223 // be used interchangably; there's no danger of interleaving access to t he | 286 // be used interchangably; there's no danger of interleaving access to t he |
224 // datastore via the two. | 287 // datastore via the two. |
225 Raw() RawInterface | 288 Raw() RawInterface |
226 } | 289 } |
OLD | NEW |