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 "fmt" | 8 "fmt" |
9 "io" | 9 "io" |
10 "io/ioutil" | 10 "io/ioutil" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 }) | 161 }) |
162 } | 162 } |
163 return filterStop(err) | 163 return filterStop(err) |
164 } | 164 } |
165 | 165 |
166 func (d *datastoreImpl) Count(q *Query) (int64, error) { | 166 func (d *datastoreImpl) Count(q *Query) (int64, error) { |
167 fq, err := q.Finalize() | 167 fq, err := q.Finalize() |
168 if err != nil { | 168 if err != nil { |
169 return 0, err | 169 return 0, err |
170 } | 170 } |
171 » return d.RawInterface.Count(fq) | 171 » v, err := d.RawInterface.Count(fq) |
| 172 » return v, filterStop(err) |
172 } | 173 } |
173 | 174 |
174 func (d *datastoreImpl) GetAll(q *Query, dst interface{}) error { | 175 func (d *datastoreImpl) GetAll(q *Query, dst interface{}) error { |
175 v := reflect.ValueOf(dst) | 176 v := reflect.ValueOf(dst) |
176 if v.Kind() != reflect.Ptr { | 177 if v.Kind() != reflect.Ptr { |
177 panic(fmt.Errorf("invalid GetAll dst: must have a ptr-to-slice:
%T", dst)) | 178 panic(fmt.Errorf("invalid GetAll dst: must have a ptr-to-slice:
%T", dst)) |
178 } | 179 } |
179 if !v.IsValid() || v.IsNil() { | 180 if !v.IsValid() || v.IsNil() { |
180 panic(errors.New("invalid GetAll dst: <nil>")) | 181 panic(errors.New("invalid GetAll dst: <nil>")) |
181 } | 182 } |
(...skipping 15 matching lines...) Expand all Loading... |
197 } | 198 } |
198 | 199 |
199 slice := v.Elem() | 200 slice := v.Elem() |
200 mat := parseMultiArg(slice.Type()) | 201 mat := parseMultiArg(slice.Type()) |
201 if mat.newElem == nil { | 202 if mat.newElem == nil { |
202 panic(fmt.Errorf("invalid GetAll dst (non-concrete element type)
: %T", dst)) | 203 panic(fmt.Errorf("invalid GetAll dst (non-concrete element type)
: %T", dst)) |
203 } | 204 } |
204 | 205 |
205 errs := map[int]error{} | 206 errs := map[int]error{} |
206 i := 0 | 207 i := 0 |
207 » err = d.RawInterface.Run(fq, func(k *Key, pm PropertyMap, _ CursorCB) er
ror { | 208 » err = filterStop(d.RawInterface.Run(fq, func(k *Key, pm PropertyMap, _ C
ursorCB) error { |
208 slice.Set(reflect.Append(slice, mat.newElem())) | 209 slice.Set(reflect.Append(slice, mat.newElem())) |
209 itm := slice.Index(i) | 210 itm := slice.Index(i) |
210 mat.setKey(itm, k) | 211 mat.setKey(itm, k) |
211 err := mat.setPM(itm, pm) | 212 err := mat.setPM(itm, pm) |
212 if err != nil { | 213 if err != nil { |
213 errs[i] = err | 214 errs[i] = err |
214 } | 215 } |
215 i++ | 216 i++ |
216 return nil | 217 return nil |
217 » }) | 218 » })) |
218 if err == nil { | 219 if err == nil { |
219 if len(errs) > 0 { | 220 if len(errs) > 0 { |
220 me := make(errors.MultiError, slice.Len()) | 221 me := make(errors.MultiError, slice.Len()) |
221 for i, e := range errs { | 222 for i, e := range errs { |
222 me[i] = e | 223 me[i] = e |
223 } | 224 } |
224 err = me | 225 err = me |
225 } | 226 } |
226 } | 227 } |
227 return err | 228 return err |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 currentDir = filepath.Dir(currentDir) | 441 currentDir = filepath.Dir(currentDir) |
441 } | 442 } |
442 } | 443 } |
443 | 444 |
444 func filterStop(err error) error { | 445 func filterStop(err error) error { |
445 if err == Stop { | 446 if err == Stop { |
446 err = nil | 447 err = nil |
447 } | 448 } |
448 return err | 449 return err |
449 } | 450 } |
OLD | NEW |