| 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 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
| 9 ) | 9 ) |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // specified parameters. | 53 // specified parameters. |
| 54 NewKey(kind, stringID string, intID int64, parent *Key) *Key | 54 NewKey(kind, stringID string, intID int64, parent *Key) *Key |
| 55 | 55 |
| 56 // NewKeyToks constructs a new key in the current appID/Namespace, using
the | 56 // NewKeyToks constructs a new key in the current appID/Namespace, using
the |
| 57 // specified key tokens. | 57 // specified key tokens. |
| 58 NewKeyToks([]KeyTok) *Key | 58 NewKeyToks([]KeyTok) *Key |
| 59 | 59 |
| 60 // KeyForObjErr extracts a key from src. | 60 // KeyForObjErr extracts a key from src. |
| 61 // | 61 // |
| 62 // src must be one of: | 62 // src must be one of: |
| 63 » // - *S where S is a struct | 63 » // - *S, where S is a struct |
| 64 // - a PropertyLoadSaver | 64 // - a PropertyLoadSaver |
| 65 // | 65 // |
| 66 // It is expected that the struct exposes the following metadata (as ret
rieved | 66 // It is expected that the struct exposes the following metadata (as ret
rieved |
| 67 // by MetaGetter.GetMeta): | 67 // by MetaGetter.GetMeta): |
| 68 // - "key" (type: Key) - The full datastore key to use. Must not be ni
l. | 68 // - "key" (type: Key) - The full datastore key to use. Must not be ni
l. |
| 69 // OR | 69 // OR |
| 70 // - "id" (type: int64 or string) - The id of the Key to create | 70 // - "id" (type: int64 or string) - The id of the Key to create |
| 71 // - "kind" (optional, type: string) - The kind of the Key to create.
If | 71 // - "kind" (optional, type: string) - The kind of the Key to create.
If |
| 72 // blank or not present, KeyForObjErr will extract the name of the s
rc | 72 // blank or not present, KeyForObjErr will extract the name of the s
rc |
| 73 // object's type. | 73 // object's type. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 92 // like nested/buffered transactions as filters. | 92 // like nested/buffered transactions as filters. |
| 93 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio
ns) error | 93 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio
ns) error |
| 94 | 94 |
| 95 // Run executes the given query, and calls `cb` for each successfully | 95 // Run executes the given query, and calls `cb` for each successfully |
| 96 // retrieved item. | 96 // retrieved item. |
| 97 // | 97 // |
| 98 // cb is a callback function whose signature is | 98 // cb is a callback function whose signature is |
| 99 // func(obj TYPE[, getCursor CursorCB]) [error] | 99 // func(obj TYPE[, getCursor CursorCB]) [error] |
| 100 // | 100 // |
| 101 // Where TYPE is one of: | 101 // Where TYPE is one of: |
| 102 » // - S or *S where S is a struct | 102 » // - S or *S, where S is a struct |
| 103 » // - P or *P where *P is a concrete type implementing PropertyLoadSave
r | 103 » // - P or *P, where *P is a concrete type implementing PropertyLoadSav
er |
| 104 // - *Key (implies a keys-only query) | 104 // - *Key (implies a keys-only query) |
| 105 // | 105 // |
| 106 // If the error is omitted from the signature, this will run until the q
uery | 106 // If the error is omitted from the signature, this will run until the q
uery |
| 107 // returns all its results, or has an error/times out. | 107 // returns all its results, or has an error/times out. |
| 108 // | 108 // |
| 109 // If error is in the signature, the query will continue as long as the | 109 // If error is in the signature, the query will continue as long as the |
| 110 // callback returns nil. If it returns `Stop`, the query will stop and R
un | 110 // callback returns nil. If it returns `Stop`, the query will stop and R
un |
| 111 // will return nil. Otherwise, the query will stop and Run will return t
he | 111 // will return nil. Otherwise, the query will stop and Run will return t
he |
| 112 // user's error. | 112 // user's error. |
| 113 // | 113 // |
| 114 // Run may also stop on the first datastore error encountered, which can
occur | 114 // Run may also stop on the first datastore error encountered, which can
occur |
| 115 // due to flakiness, timeout, etc. If it encounters such an error, it wi
ll | 115 // due to flakiness, timeout, etc. If it encounters such an error, it wi
ll |
| 116 // be returned. | 116 // be returned. |
| 117 Run(q *Query, cb interface{}) error | 117 Run(q *Query, cb interface{}) error |
| 118 | 118 |
| 119 // Count executes the given query and returns the number of entries whic
h | 119 // Count executes the given query and returns the number of entries whic
h |
| 120 // match it. | 120 // match it. |
| 121 Count(q *Query) (int64, error) | 121 Count(q *Query) (int64, error) |
| 122 | 122 |
| 123 // DecodeCursor converts a string returned by a Cursor into a Cursor ins
tance. | 123 // DecodeCursor converts a string returned by a Cursor into a Cursor ins
tance. |
| 124 // It will return an error if the supplied string is not valid, or could
not | 124 // It will return an error if the supplied string is not valid, or could
not |
| 125 // be decoded by the implementation. | 125 // be decoded by the implementation. |
| 126 DecodeCursor(string) (Cursor, error) | 126 DecodeCursor(string) (Cursor, error) |
| 127 | 127 |
| 128 // GetAll retrieves all of the Query results into dst. | 128 // GetAll retrieves all of the Query results into dst. |
| 129 // | 129 // |
| 130 // dst must be one of: | 130 // dst must be one of: |
| 131 » // - *[]S or *[]*S where S is a struct | 131 » // - *[]S or *[]*S, where S is a struct |
| 132 » // - *[]P or *[]*P where *P is a concrete type implementing | 132 » // - *[]P or *[]*P, where *P is a concrete type implementing |
| 133 // PropertyLoadSaver | 133 // PropertyLoadSaver |
| 134 // - *[]*Key implies a keys-only query. | 134 // - *[]*Key implies a keys-only query. |
| 135 GetAll(q *Query, dst interface{}) error | 135 GetAll(q *Query, dst interface{}) error |
| 136 | 136 |
| 137 // Exists tests if the supplied objects are present in the datastore. | 137 // Exists tests if the supplied objects are present in the datastore. |
| 138 // | 138 // |
| 139 // ent must be one of: | 139 // ent must be one of: |
| 140 » //» - *S where S is a struct | 140 » //» - *S, where S is a struct |
| 141 » //» - *P where *P is a concrete type implementing PropertyLoadSaver | 141 » //» - *P, where *P is a concrete type implementing PropertyLoadSaver |
| 142 » //» - []S or []*S where S is a struct | 142 » //» - []S or []*S, where S is a struct |
| 143 » //» - []P or []*P where *P is a concrete type implementing PropertyL
oadSaver | 143 » //» - []P or []*P, where *P is a concrete type implementing Property
LoadSaver |
| 144 » //» - []I where i is some interface type. Each element of the slice
must | 144 » //» - []I, where I is some interface type. Each element of the slice
must |
| 145 // be non-nil, and its underlying type must be either *S or *P. | 145 // be non-nil, and its underlying type must be either *S or *P. |
| 146 // - *Key, to check a specific key from the datastore. | 146 // - *Key, to check a specific key from the datastore. |
| 147 // - []*Key, to check a slice of keys from the datastore. | 147 // - []*Key, to check a slice of keys from the datastore. |
| 148 // | 148 // |
| 149 // If an error is encountered, the returned error value will depend on t
he | 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 | 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 | 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 | 152 // be a MultiError whose error index corresponds to the argument in whic
h the |
| 153 // error was encountered. | 153 // error was encountered. |
| 154 // | 154 // |
| 155 // If an ent argument is a slice, its error type will be a MultiError. N
ote | 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 | 156 » // that in the scenario, where multiple slices are provided, this will r
eturn a |
| 157 // MultiError containing a nested MultiError for each slice argument. | 157 // MultiError containing a nested MultiError for each slice argument. |
| 158 Exists(ent ...interface{}) (*ExistsResult, error) | 158 Exists(ent ...interface{}) (*ExistsResult, error) |
| 159 | 159 |
| 160 // 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 |
| 161 » // 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 |
| 162 » // than using Get directly, because it uses the underlying RawInterface
to | 162 » // efficient than using Get directly, because it uses the underlying |
| 163 » // avoid some reflection and copies. | 163 » // RawInterface to avoid some reflection and copies. |
| 164 // | 164 // |
| 165 // If an error is encountered, the returned error will be a MultiError w
hose | 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. | 166 // error index corresponds to the key for which the error was encountere
d. |
| 167 // | 167 // |
| 168 // NOTE: ExistsMulti is obsolete. The vararg-accepting Exists should be
used | 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 | 169 // instead. This is left for backwards compatibility, but will be remove
d from |
| 170 // this interface at some point in the future. | 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 objects from the datastore. | 173 // Get retrieves objects from the datastore. |
| 174 // | 174 // |
| 175 // Each element in 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 » //» - []S or []*S where S is a struct | 178 » //» - []S or []*S, where S is a struct |
| 179 » //» - []P or []*P where *P is a concrete type implementing PropertyL
oadSaver | 179 » //» - []P or []*P, where *P is a concrete type implementing Property
LoadSaver |
| 180 » //» - []I where I is some interface type. Each element of the slice
must | 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 // be non-nil, and its underlying type must be either *S or *P. |
| 182 // | 182 // |
| 183 // If an error is encountered, the returned error value will depend on t
he | 183 // If an error is encountered, the returned error value will depend on t
he |
| 184 // input arguments. If one argument is supplied, the result will be the | 184 // input arguments. If one argument is supplied, the result will be the |
| 185 // encountered error type. If multiple arguments are supplied, the resul
t will | 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 | 186 // be a MultiError whose error index corresponds to the argument in whic
h the |
| 187 // error was encountered. | 187 // error was encountered. |
| 188 // | 188 // |
| 189 // If a dst argument is a slice, its error type will be a MultiError. No
te | 189 // If a dst argument is a slice, its error type will be a MultiError. No
te |
| 190 // that in the scenario where multiple slices are provided, this will re
turn a | 190 // that in the scenario where multiple slices are provided, this will re
turn a |
| 191 // MultiError containing a nested MultiError for each slice argument. | 191 // MultiError containing a nested MultiError for each slice argument. |
| 192 Get(dst ...interface{}) error | 192 Get(dst ...interface{}) 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 PropertyLoa
dSaver |
| 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 mu
st |
| 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 // | 201 // |
| 202 // NOTE: GetMulti is obsolete. The vararg-accepting Get should be used | 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 | 203 // instead. This is left for backwards compatibility, but will be remove
d from |
| 204 // this interface at some point in the future. | 204 // this interface at some point in the future. |
| 205 GetMulti(dst interface{}) error | 205 GetMulti(dst interface{}) error |
| 206 | 206 |
| 207 // Put inserts a single object into the datastore | 207 // Put inserts a single object into the datastore |
| 208 // | 208 // |
| 209 // src must be one of: | 209 // src must be one of: |
| 210 » //» - *S where S is a struct | 210 » //» - *S, where S is a struct |
| 211 » //» - *P where *P is a concrete type implementing PropertyLoadSaver | 211 » //» - *P, where *P is a concrete type implementing PropertyLoadSaver |
| 212 » //» - []S or []*S where S is a struct | 212 » //» - []S or []*S, where S is a struct |
| 213 » //» - []P or []*P where *P is a concrete type implementing PropertyL
oadSaver | 213 » //» - []P or []*P, where *P is a concrete type implementing Property
LoadSaver |
| 214 » //» - []I where i is some interface type. Each element of the slice
must | 214 » //» - []I, where I is some interface type. Each element of the slice
must |
| 215 // be non-nil, and its underlying type must be either *S or *P. | 215 // be non-nil, and its underlying type must be either *S or *P. |
| 216 // | 216 // |
| 217 // A *Key will be extracted from src via KeyForObj. If | 217 // A *Key will be extracted from src via KeyForObj. If |
| 218 // extractedKey.Incomplete() is true, then Put will write the resolved (
i.e. | 218 // extractedKey.Incomplete() is true, then Put will write the resolved (
i.e. |
| 219 // automatic datastore-populated) *Key back to src. | 219 // automatic datastore-populated) *Key back to src. |
| 220 // | 220 // |
| 221 // If an error is encountered, the returned error value will depend on t
he | 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 | 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 | 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 | 224 // be a MultiError whose error index corresponds to the argument in whic
h the |
| 225 // error was encountered. | 225 // error was encountered. |
| 226 // | 226 // |
| 227 // If a src argument is a slice, its error type will be a MultiError. No
te | 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 | 228 // that in the scenario where multiple slices are provided, this will re
turn a |
| 229 // MultiError containing a nested MultiError for each slice argument. | 229 // MultiError containing a nested MultiError for each slice argument. |
| 230 Put(src ...interface{}) error | 230 Put(src ...interface{}) error |
| 231 | 231 |
| 232 // PutMulti writes items to the datastore. | 232 // PutMulti writes items to the datastore. |
| 233 // | 233 // |
| 234 // src must be one of: | 234 // src must be one of: |
| 235 » //» - []S or []*S where S is a struct | 235 » //» - []S or []*S, where S is a struct |
| 236 » //» - []P or []*P where *P is a concrete type implementing PropertyL
oadSaver | 236 » //» - []P or []*P, where *P is a concrete type implementing Property
LoadSaver |
| 237 » //» - []I where i is some interface type. Each element of the slice
must | 237 » //» - []I, where I is some interface type. Each element of the slice
must |
| 238 // 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. |
| 239 // | 239 // |
| 240 // 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 |
| 241 // resolved keys back to the items in src. | 241 // resolved keys back to the items in src. |
| 242 // | 242 // |
| 243 // NOTE: PutMulti is obsolete. The vararg-accepting Put should be used | 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 | 244 // instead. This is left for backwards compatibility, but will be remove
d from |
| 245 // this interface at some point in the future. | 245 // this interface at some point in the future. |
| 246 PutMulti(src interface{}) error | 246 PutMulti(src interface{}) error |
| 247 | 247 |
| 248 // Delete removes the supplied entities from the datastore. | 248 // Delete removes the supplied entities from the datastore. |
| 249 // | 249 // |
| 250 // ent must be one of: | 250 // ent must be one of: |
| 251 » //» - *S where S is a struct | 251 » //» - *S, where S is a struct |
| 252 » //» - *P where *P is a concrete type implementing PropertyLoadSaver | 252 » //» - *P, where *P is a concrete type implementing PropertyLoadSaver |
| 253 » //» - []S or []*S where S is a struct | 253 » //» - []S or []*S, where S is a struct |
| 254 » //» - []P or []*P where *P is a concrete type implementing PropertyL
oadSaver | 254 » //» - []P or []*P, where *P is a concrete type implementing Property
LoadSaver |
| 255 » //» - []I where i is some interface type. Each element of the slice
must | 255 » //» - []I, where I is some interface type. Each element of the slice
must |
| 256 // be non-nil, and its underlying type must be either *S or *P. | 256 // be non-nil, and its underlying type must be either *S or *P. |
| 257 // - *Key, to remove a specific key from the datastore. | 257 // - *Key, to remove a specific key from the datastore. |
| 258 // - []*Key, to remove a slice of keys from the datastore. | 258 // - []*Key, to remove a slice of keys from the datastore. |
| 259 // | 259 // |
| 260 // If an error is encountered, the returned error value will depend on t
he | 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 | 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 | 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 | 263 // be a MultiError whose error index corresponds to the argument in whic
h the |
| 264 // error was encountered. | 264 // error was encountered. |
| 265 // | 265 // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 280 | 280 |
| 281 // 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 |
| 282 // there is none. | 282 // there is none. |
| 283 Testable() Testable | 283 Testable() Testable |
| 284 | 284 |
| 285 // Raw returns the underlying RawInterface. The Interface and RawInterfa
ce may | 285 // Raw returns the underlying RawInterface. The Interface and RawInterfa
ce may |
| 286 // 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 |
| 287 // datastore via the two. | 287 // datastore via the two. |
| 288 Raw() RawInterface | 288 Raw() RawInterface |
| 289 } | 289 } |
| OLD | NEW |