| 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 "fmt" | 8 "fmt" |
| 9 | 9 |
| 10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // | 35 // |
| 36 // - val is the data of the entity | 36 // - val is the data of the entity |
| 37 // * 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 |
| 38 // keys are validated before the RPC occurs! | 38 // keys are validated before the RPC occurs! |
| 39 // - err is an error associated with this entity (e.g. ErrNoSuchEntity). | 39 // - err is an error associated with this entity (e.g. ErrNoSuchEntity). |
| 40 // | 40 // |
| 41 // Return nil to continue iterating, or an error to stop. If you return the | 41 // Return nil to continue iterating, or an error to stop. If you return the |
| 42 // error `Stop`, then GetMulti will stop the query and return nil. | 42 // error `Stop`, then GetMulti will stop the query and return nil. |
| 43 type GetMultiCB func(val PropertyMap, err error) error | 43 type GetMultiCB func(val PropertyMap, err error) error |
| 44 | 44 |
| 45 // PutMultiCB is the callback signature provided to RawInterface.PutMulti | 45 // NewKeyCB is the callback signature provided to RawInterface.PutMulti and |
| 46 // RawInterface.AllocateIDs. It is invoked once for each positional key that |
| 47 // was generated as the result of a call. |
| 46 // | 48 // |
| 47 // - key is the new key for the entity (if the original was incomplete) | 49 // - key is the new key for the entity (if the original was incomplete) |
| 48 // * It may be nil if some of the keys/vals to the PutMulti were bad, since | 50 // * It may be nil if some of the keys/vals to the PutMulti were bad, since |
| 49 // all keys are validated before the RPC occurs! | 51 // all keys are validated before the RPC occurs! |
| 50 // - err is an error associated with putting this entity. | 52 // - err is an error associated with putting this entity. |
| 51 // | 53 // |
| 52 // Return nil to continue iterating, or an error to stop. If you return the | 54 // Return nil to continue iterating, or an error to stop. If you return the |
| 53 // error `Stop`, then PutMulti will stop the query and return nil. | 55 // error `Stop`, then PutMulti will stop the query and return nil. |
| 54 type PutMultiCB func(key *Key, err error) error | 56 type NewKeyCB func(key *Key, err error) error |
| 55 | 57 |
| 56 // DeleteMultiCB is the callback signature provided to RawInterface.DeleteMulti | 58 // DeleteMultiCB is the callback signature provided to RawInterface.DeleteMulti |
| 57 // | 59 // |
| 58 // - err is an error associated with deleting this entity. | 60 // - err is an error associated with deleting this entity. |
| 59 // | 61 // |
| 60 // Return nil to continue iterating, or an error to stop. If you return the | 62 // Return nil to continue iterating, or an error to stop. If you return the |
| 61 // error `Stop`, then DeleteMulti will stop the query and return nil. | 63 // error `Stop`, then DeleteMulti will stop the query and return nil. |
| 62 type DeleteMultiCB func(err error) error | 64 type DeleteMultiCB func(err error) error |
| 63 | 65 |
| 64 type nullMetaGetterType struct{} | 66 type nullMetaGetterType struct{} |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return nullMetaGetter | 100 return nullMetaGetter |
| 99 } | 101 } |
| 100 return m[idx] | 102 return m[idx] |
| 101 } | 103 } |
| 102 | 104 |
| 103 // RawInterface implements the datastore functionality without any of the fancy | 105 // RawInterface implements the datastore functionality without any of the fancy |
| 104 // reflection stuff. This is so that Filters can avoid doing lots of redundant | 106 // reflection stuff. This is so that Filters can avoid doing lots of redundant |
| 105 // reflection work. See datastore.Interface for a more user-friendly interface. | 107 // reflection work. See datastore.Interface for a more user-friendly interface. |
| 106 type RawInterface interface { | 108 type RawInterface interface { |
| 107 // AllocateIDs allows you to allocate IDs from the datastore without put
ting | 109 // AllocateIDs allows you to allocate IDs from the datastore without put
ting |
| 108 » // any data. `incomplete` must be a PartialValid Key. If there's no erro
r, | 110 » // any data. The supplied keys must be PartialValid and share the same e
ntity |
| 109 » // a contiguous block of IDs of n length starting at `start` will be res
erved | 111 » // type. |
| 110 » // indefinitely for the user application code for use in new keys. The | 112 » // |
| 111 » // appengine automatic ID generator will never automatically assign thes
e IDs | 113 » // If there's no error, the keys in the slice will be replaced with keys |
| 112 » // for Keys of this type. | 114 » // containing integer IDs assigned to them. |
| 113 » AllocateIDs(incomplete *Key, n int) (start int64, err error) | 115 » AllocateIDs(keys []*Key, cb NewKeyCB) error |
| 114 | 116 |
| 115 // RunInTransaction runs f in a transaction. | 117 // RunInTransaction runs f in a transaction. |
| 116 // | 118 // |
| 117 // opts may be nil. | 119 // opts may be nil. |
| 118 // | 120 // |
| 119 // NOTE: Implementations and filters are guaranteed that: | 121 // NOTE: Implementations and filters are guaranteed that: |
| 120 // - f is not nil | 122 // - f is not nil |
| 121 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio
ns) error | 123 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio
ns) error |
| 122 | 124 |
| 123 // DecodeCursor converts a string returned by a Cursor into a Cursor ins
tance. | 125 // DecodeCursor converts a string returned by a Cursor into a Cursor ins
tance. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 153 // PutMulti writes items to the datastore. | 155 // PutMulti writes items to the datastore. |
| 154 // | 156 // |
| 155 // Callback execues once per key/value pair, in the passed-in order. Cal
lback | 157 // Callback execues once per key/value pair, in the passed-in order. Cal
lback |
| 156 // may not execute at all if there was a server error. | 158 // may not execute at all if there was a server error. |
| 157 // | 159 // |
| 158 // NOTE: Implementations and filters are guaranteed that: | 160 // NOTE: Implementations and filters are guaranteed that: |
| 159 // - len(keys) > 0 | 161 // - len(keys) > 0 |
| 160 // - len(keys) == len(vals) | 162 // - len(keys) == len(vals) |
| 161 // - all keys are Valid and in the current namespace | 163 // - all keys are Valid and in the current namespace |
| 162 // - cb is not nil | 164 // - cb is not nil |
| 163 » PutMulti(keys []*Key, vals []PropertyMap, cb PutMultiCB) error | 165 » PutMulti(keys []*Key, vals []PropertyMap, cb NewKeyCB) error |
| 164 | 166 |
| 165 // DeleteMulti removes items from the datastore. | 167 // DeleteMulti removes items from the datastore. |
| 166 // | 168 // |
| 167 // Callback execues once per key, in the order of keys. Callback may not | 169 // Callback execues once per key, in the order of keys. Callback may not |
| 168 // execute at all if there's a server error. | 170 // execute at all if there's a server error. |
| 169 // | 171 // |
| 170 // NOTE: Implementations and filters are guaranteed that | 172 // NOTE: Implementations and filters are guaranteed that |
| 171 // - len(keys) > 0 | 173 // - len(keys) > 0 |
| 172 // - all keys are Valid, !Incomplete, and in the current namespace | 174 // - all keys are Valid, !Incomplete, and in the current namespace |
| 173 // - none keys of the keys are 'special' (use a kind prefixed with '__
') | 175 // - none keys of the keys are 'special' (use a kind prefixed with '__
') |
| 174 // - cb is not nil | 176 // - cb is not nil |
| 175 DeleteMulti(keys []*Key, cb DeleteMultiCB) error | 177 DeleteMulti(keys []*Key, cb DeleteMultiCB) error |
| 176 | 178 |
| 177 // Testable returns the Testable interface for the implementation, or ni
l if | 179 // Testable returns the Testable interface for the implementation, or ni
l if |
| 178 // there is none. | 180 // there is none. |
| 179 Testable() Testable | 181 Testable() Testable |
| 180 } | 182 } |
| OLD | NEW |