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 | 9 |
10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
11 ) | 11 ) |
12 | 12 |
13 // Cursor wraps datastore.Cursor. | 13 // Cursor wraps datastore.Cursor. |
14 type Cursor interface { | 14 type Cursor interface { |
15 fmt.Stringer | 15 fmt.Stringer |
16 } | 16 } |
17 | 17 |
18 // CursorCB is used to obtain a Cursor while Run'ing a query on either | 18 // CursorCB is used to obtain a Cursor while Run'ing a query on either |
19 // Interface or RawInterface. | 19 // Interface or RawInterface. |
20 // | 20 // |
21 // it can be invoked to obtain the current cursor. | 21 // it can be invoked to obtain the current cursor. |
22 type CursorCB func() (Cursor, error) | 22 type CursorCB func() (Cursor, error) |
23 | 23 |
24 // RawRunCB is the callback signature provided to RawInterface.Run | 24 // RawRunCB is the callback signature provided to RawInterface.Run |
25 // | 25 // |
26 // - key is the Key of the entity | 26 // - key is the Key of the entity |
27 // - val is the data of the entity (or nil, if the query was keys-only) | 27 // - val is the data of the entity (or nil, if the query was keys-only) |
28 // | 28 // |
29 // Return true to continue iterating through the query results, or false to stop
. | 29 // Return nil to continue iterating through the query results, or an error to |
30 type RawRunCB func(key *Key, val PropertyMap, getCursor CursorCB) bool | 30 // stop. If you return the error `Stop`, then Run will stop the query and |
| 31 // return nil. |
| 32 type RawRunCB func(key *Key, val PropertyMap, getCursor CursorCB) error |
31 | 33 |
32 // GetMultiCB is the callback signature provided to RawInterface.GetMulti | 34 // GetMultiCB is the callback signature provided to RawInterface.GetMulti |
33 // | 35 // |
34 // - val is the data of the entity | 36 // - val is the data of the entity |
35 // * It may be nil if some of the keys to the GetMulti were bad, since all | 37 // * It may be nil if some of the keys to the GetMulti were bad, since all |
36 // keys are validated before the RPC occurs! | 38 // keys are validated before the RPC occurs! |
37 // - err is an error associated with this entity (e.g. ErrNoSuchEntity). | 39 // - err is an error associated with this entity (e.g. ErrNoSuchEntity). |
38 type GetMultiCB func(val PropertyMap, err error) | 40 type GetMultiCB func(val PropertyMap, err error) error |
39 | 41 |
40 // PutMultiCB is the callback signature provided to RawInterface.PutMulti | 42 // PutMultiCB is the callback signature provided to RawInterface.PutMulti |
41 // | 43 // |
42 // - key is the new key for the entity (if the original was incomplete) | 44 // - key is the new key for the entity (if the original was incomplete) |
43 // * It may be nil if some of the keys/vals to the PutMulti were bad, since | 45 // * It may be nil if some of the keys/vals to the PutMulti were bad, since |
44 // all keys are validated before the RPC occurs! | 46 // all keys are validated before the RPC occurs! |
45 // - err is an error associated with putting this entity. | 47 // - err is an error associated with putting this entity. |
46 type PutMultiCB func(key *Key, err error) | 48 type PutMultiCB func(key *Key, err error) error |
47 | 49 |
48 // DeleteMultiCB is the callback signature provided to RawInterface.DeleteMulti | 50 // DeleteMultiCB is the callback signature provided to RawInterface.DeleteMulti |
49 // | 51 // |
50 // - err is an error associated with deleting this entity. | 52 // - err is an error associated with deleting this entity. |
51 type DeleteMultiCB func(err error) | 53 type DeleteMultiCB func(err error) error |
52 | 54 |
53 type nullMetaGetterType struct{} | 55 type nullMetaGetterType struct{} |
54 | 56 |
55 func (nullMetaGetterType) GetMeta(string) (interface{}, bool) { return nil, fals
e } | 57 func (nullMetaGetterType) GetMeta(string) (interface{}, bool) { return nil, fals
e } |
56 | 58 |
57 var nullMetaGetter MetaGetter = nullMetaGetterType{} | 59 var nullMetaGetter MetaGetter = nullMetaGetterType{} |
58 | 60 |
59 // MultiMetaGetter is a carrier for metadata, used with RawInterface.GetMulti | 61 // MultiMetaGetter is a carrier for metadata, used with RawInterface.GetMulti |
60 // | 62 // |
61 // It's OK to default-construct this. GetMeta will just return | 63 // It's OK to default-construct this. GetMeta will just return |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // - len(keys) > 0 | 162 // - len(keys) > 0 |
161 // - all keys are Valid, !Incomplete, and in the current namespace | 163 // - all keys are Valid, !Incomplete, and in the current namespace |
162 // - none keys of the keys are 'special' (use a kind prefixed with '__
') | 164 // - none keys of the keys are 'special' (use a kind prefixed with '__
') |
163 // - cb is not nil | 165 // - cb is not nil |
164 DeleteMulti(keys []*Key, cb DeleteMultiCB) error | 166 DeleteMulti(keys []*Key, cb DeleteMultiCB) error |
165 | 167 |
166 // Testable returns the Testable interface for the implementation, or ni
l if | 168 // Testable returns the Testable interface for the implementation, or ni
l if |
167 // there is none. | 169 // there is none. |
168 Testable() Testable | 170 Testable() Testable |
169 } | 171 } |
OLD | NEW |