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 |
11 // Interface is the 'user-friendly' interface to access the current filtered | 35 // Interface is the 'user-friendly' interface to access the current filtered |
12 // datastore service implementation. | 36 // datastore service implementation. |
13 // | 37 // |
14 // Note that in exchange for userfriendliness, this interface ends up doing | 38 // Note that in exchange for userfriendliness, this interface ends up doing |
15 // a lot of reflection. | 39 // a lot of reflection. |
16 // | 40 // |
17 // Methods taking 'interface{}' objects describe what a valid type for that | 41 // Methods taking 'interface{}' objects describe what a valid type for that |
18 // interface are in the comments. | 42 // interface are in the comments. |
19 // | 43 // |
20 // Struct objects passed in will be converted to PropertyLoadSaver interfaces | 44 // Struct objects passed in will be converted to PropertyLoadSaver interfaces |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // Does a Get for this key and returns true iff it exists. Will only ret
urn | 161 // Does a Get for this key and returns true iff it exists. Will only ret
urn |
138 // an error if it's not ErrNoSuchEntity. This is slightly more efficient | 162 // an error if it's not ErrNoSuchEntity. This is slightly more efficient |
139 // than using Get directly, because it uses the underlying RawInterface
to | 163 // than using Get directly, because it uses the underlying RawInterface
to |
140 // avoid some reflection and copies. | 164 // avoid some reflection and copies. |
141 Exists(k *Key) (bool, error) | 165 Exists(k *Key) (bool, error) |
142 | 166 |
143 // Does a GetMulti for thes keys and returns true iff they exist. Will o
nly | 167 // Does a GetMulti for thes keys and returns true iff they exist. Will o
nly |
144 // return an error if it's not ErrNoSuchEntity. This is slightly more ef
ficient | 168 // return an error if it's not ErrNoSuchEntity. This is slightly more ef
ficient |
145 // than using Get directly, because it uses the underlying RawInterface
to | 169 // than using Get directly, because it uses the underlying RawInterface
to |
146 // avoid some reflection and copies. | 170 // avoid some reflection and copies. |
147 » ExistsMulti(k []*Key) ([]bool, error) | 171 » ExistsMulti(k []*Key) (BoolList, error) |
148 | 172 |
149 // Get retrieves a single object from the datastore | 173 // Get retrieves a single object from the datastore |
150 // | 174 // |
151 // dst must be one of: | 175 // dst must be one of: |
152 // - *S where S is a struct | 176 // - *S where S is a struct |
153 // - *P where *P is a concrete type implementing PropertyLoadSaver | 177 // - *P where *P is a concrete type implementing PropertyLoadSaver |
154 Get(dst interface{}) error | 178 Get(dst interface{}) error |
155 | 179 |
156 // Put inserts a single object into the datastore | 180 // Put inserts a single object into the datastore |
157 // | 181 // |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 217 |
194 // Testable returns the Testable interface for the implementation, or ni
l if | 218 // Testable returns the Testable interface for the implementation, or ni
l if |
195 // there is none. | 219 // there is none. |
196 Testable() Testable | 220 Testable() Testable |
197 | 221 |
198 // Raw returns the underlying RawInterface. The Interface and RawInterfa
ce may | 222 // Raw returns the underlying RawInterface. The Interface and RawInterfa
ce may |
199 // be used interchangably; there's no danger of interleaving access to t
he | 223 // be used interchangably; there's no danger of interleaving access to t
he |
200 // datastore via the two. | 224 // datastore via the two. |
201 Raw() RawInterface | 225 Raw() RawInterface |
202 } | 226 } |
OLD | NEW |