| 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 rawdatastore | 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 // Key is the equivalent of *datastore.Key from the original SDK, except that | 13 // Key is the equivalent of *datastore.Key from the original SDK, except that |
| 14 // it can have multiple implementations. See helper.Key* methods for missing | 14 // it can have multiple implementations. See helper.Key* methods for missing |
| 15 // methods like KeyIncomplete (and some new ones like KeyValid). | 15 // methods like KeyIncomplete (and some new ones like KeyValid). |
| (...skipping 28 matching lines...) Expand all Loading... |
| 44 EventualConsistency() Query | 44 EventualConsistency() Query |
| 45 Filter(filterStr string, value interface{}) Query | 45 Filter(filterStr string, value interface{}) Query |
| 46 KeysOnly() Query | 46 KeysOnly() Query |
| 47 Limit(limit int) Query | 47 Limit(limit int) Query |
| 48 Offset(offset int) Query | 48 Offset(offset int) Query |
| 49 Order(fieldName string) Query | 49 Order(fieldName string) Query |
| 50 Project(fieldNames ...string) Query | 50 Project(fieldNames ...string) Query |
| 51 Start(c Cursor) Query | 51 Start(c Cursor) Query |
| 52 } | 52 } |
| 53 | 53 |
| 54 // RunCB is the callback signature provided to Interface.Run | 54 // RawRunCB is the callback signature provided to RawInterface.Run |
| 55 // | 55 // |
| 56 // - key is the Key of the entity | 56 // - key is the Key of the entity |
| 57 // - val is the data of the entity (or nil, if the query was keys-only) | 57 // - val is the data of the entity (or nil, if the query was keys-only) |
| 58 // - getCursor can be invoked to obtain the current cursor. | 58 // - getCursor can be invoked to obtain the current cursor. |
| 59 // | 59 // |
| 60 // Return true to continue iterating through the query results, or false to stop
. | 60 // Return true to continue iterating through the query results, or false to stop
. |
| 61 type RunCB func(key Key, val PropertyMap, getCursor func() (Cursor, error)) bool | 61 type RawRunCB func(key Key, val PropertyMap, getCursor func() (Cursor, error)) b
ool |
| 62 | 62 |
| 63 // GetMultiCB is the callback signature provided to Interface.GetMulti | 63 // GetMultiCB is the callback signature provided to RawInterface.GetMulti |
| 64 // | 64 // |
| 65 // - val is the data of the entity | 65 // - val is the data of the entity |
| 66 // * It may be nil if some of the keys to the GetMulti were bad, since all | 66 // * It may be nil if some of the keys to the GetMulti were bad, since all |
| 67 // keys are validated before the RPC occurs! | 67 // keys are validated before the RPC occurs! |
| 68 // - err is an error associated with this entity (e.g. ErrNoSuchEntity). | 68 // - err is an error associated with this entity (e.g. ErrNoSuchEntity). |
| 69 type GetMultiCB func(val PropertyMap, err error) | 69 type GetMultiCB func(val PropertyMap, err error) |
| 70 | 70 |
| 71 // PutMultiCB is the callback signature provided to Interface.PutMulti | 71 // PutMultiCB is the callback signature provided to RawInterface.PutMulti |
| 72 // | 72 // |
| 73 // - key is the new key for the entity (if the original was incomplete) | 73 // - key is the new key for the entity (if the original was incomplete) |
| 74 // * It may be nil if some of the keys/vals to the PutMulti were bad, since | 74 // * It may be nil if some of the keys/vals to the PutMulti were bad, since |
| 75 // all keys are validated before the RPC occurs! | 75 // all keys are validated before the RPC occurs! |
| 76 // - err is an error associated with putting this entity. | 76 // - err is an error associated with putting this entity. |
| 77 type PutMultiCB func(key Key, err error) | 77 type PutMultiCB func(key Key, err error) |
| 78 | 78 |
| 79 // DeleteMultiCB is the callback signature provided to Interface.DeleteMulti | 79 // DeleteMultiCB is the callback signature provided to RawInterface.DeleteMulti |
| 80 // | 80 // |
| 81 // - err is an error associated with deleting this entity. | 81 // - err is an error associated with deleting this entity. |
| 82 type DeleteMultiCB func(err error) | 82 type DeleteMultiCB func(err error) |
| 83 | 83 |
| 84 // Interface implements the datastore functionality without any of the fancy | 84 // RawInterface implements the datastore functionality without any of the fancy |
| 85 // reflection stuff. This is so that Filters can avoid doing lots of redundant | 85 // reflection stuff. This is so that Filters can avoid doing lots of redundant |
| 86 // reflection work. See datastore.Interface for a more user-friendly interface. | 86 // reflection work. See datastore.RawInterface for a more user-friendly interfac
e. |
| 87 type Interface interface { | 87 type RawInterface interface { |
| 88 NewKey(kind, stringID string, intID int64, parent Key) Key | 88 NewKey(kind, stringID string, intID int64, parent Key) Key |
| 89 DecodeKey(encoded string) (Key, error) | 89 DecodeKey(encoded string) (Key, error) |
| 90 NewQuery(kind string) Query | 90 NewQuery(kind string) Query |
| 91 | 91 |
| 92 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio
ns) error | 92 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio
ns) error |
| 93 | 93 |
| 94 // Run executes the given query, and calls `cb` for each successfully it
em. | 94 // Run executes the given query, and calls `cb` for each successfully it
em. |
| 95 » Run(q Query, cb RunCB) error | 95 » Run(q Query, cb RawRunCB) error |
| 96 | 96 |
| 97 // GetMulti retrieves items from the datastore. | 97 // GetMulti retrieves items from the datastore. |
| 98 // | 98 // |
| 99 // Callback execues once per key, in the order of keys. Callback may not | 99 // Callback execues once per key, in the order of keys. Callback may not |
| 100 // execute at all if there's a server error. If callback is nil, this | 100 // execute at all if there's a server error. If callback is nil, this |
| 101 // method does nothing. | 101 // method does nothing. |
| 102 // | 102 // |
| 103 // NOTE: Implementations and filters are guaranteed that keys are all Va
lid | 103 // NOTE: Implementations and filters are guaranteed that keys are all Va
lid |
| 104 // and Complete, and in the correct namespace. | 104 // and Complete, and in the correct namespace. |
| 105 GetMulti(keys []Key, cb GetMultiCB) error | 105 GetMulti(keys []Key, cb GetMultiCB) error |
| 106 | 106 |
| 107 // PutMulti writes items to the datastore. | 107 // PutMulti writes items to the datastore. |
| 108 // | 108 // |
| 109 // Callback execues once per item, in the order of itemss. Callback may
not | 109 // Callback execues once per item, in the order of itemss. Callback may
not |
| 110 // execute at all if there's a server error. | 110 // execute at all if there's a server error. |
| 111 // | 111 // |
| 112 // NOTE: Implementations and filters are guaranteed that len(keys) == | 112 // NOTE: Implementations and filters are guaranteed that len(keys) == |
| 113 // len(vals), that keys are all Valid, and in the correct namespace. | 113 // len(vals), that keys are all Valid, and in the correct namespace. |
| 114 » // Additionally, vals are guaranteed to be PropertyMaps already. Callbac
k | 114 » // Callback may be nil. |
| 115 » // may be nil. | 115 » PutMulti(keys []Key, vals []PropertyMap, cb PutMultiCB) error |
| 116 » PutMulti(keys []Key, vals []PropertyLoadSaver, cb PutMultiCB) error | |
| 117 | 116 |
| 118 // DeleteMulti removes items from the datastore. | 117 // DeleteMulti removes items from the datastore. |
| 119 // | 118 // |
| 120 // Callback execues once per key, in the order of keys. Callback may not | 119 // Callback execues once per key, in the order of keys. Callback may not |
| 121 // execute at all if there's a server error. | 120 // execute at all if there's a server error. |
| 122 // | 121 // |
| 123 // NOTE: Implementations and filters are guaranteed that keys are all Va
lid | 122 // NOTE: Implementations and filters are guaranteed that keys are all Va
lid |
| 124 // and Complete, and in the correct namespace, and are not 'special'. | 123 // and Complete, and in the correct namespace, and are not 'special'. |
| 125 // Callback may be nil. | 124 // Callback may be nil. |
| 126 DeleteMulti(keys []Key, cb DeleteMultiCB) error | 125 DeleteMulti(keys []Key, cb DeleteMultiCB) error |
| 127 } | 126 } |
| OLD | NEW |