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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 runs f in a transaction. |
| 93 // |
| 94 // opts may be nil. |
| 95 // |
| 96 // NOTE: Implementations and filters are guaranteed that: |
| 97 // - f is not nil |
92 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio
ns) error | 98 RunInTransaction(f func(c context.Context) error, opts *TransactionOptio
ns) error |
93 | 99 |
94 // Run executes the given query, and calls `cb` for each successfully it
em. | 100 // Run executes the given query, and calls `cb` for each successfully it
em. |
95 » Run(q Query, cb RunCB) error | 101 » // |
| 102 » // NOTE: Implementations and filters are guaranteed that: |
| 103 » // - query is not nil |
| 104 » // - cb is not nil |
| 105 » Run(q Query, cb RawRunCB) error |
96 | 106 |
97 // GetMulti retrieves items from the datastore. | 107 // GetMulti retrieves items from the datastore. |
98 // | 108 // |
99 // Callback execues once per key, in the order of keys. Callback may not | 109 // 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 | 110 // execute at all if there's a server error. If callback is nil, this |
101 // method does nothing. | 111 // method does nothing. |
102 // | 112 // |
103 » // NOTE: Implementations and filters are guaranteed that keys are all Va
lid | 113 » // NOTE: Implementations and filters are guaranteed that: |
104 » // and Complete, and in the correct namespace. | 114 » // - len(keys) > 0 |
| 115 » // - all keys are Valid, !Incomplete, and in the current namespace |
| 116 » // - cb is not nil |
105 GetMulti(keys []Key, cb GetMultiCB) error | 117 GetMulti(keys []Key, cb GetMultiCB) error |
106 | 118 |
107 // PutMulti writes items to the datastore. | 119 // PutMulti writes items to the datastore. |
108 // | 120 // |
109 » // Callback execues once per item, in the order of itemss. Callback may
not | 121 » // Callback execues once per key/value pair, in the passed-in order. Cal
lback |
110 » // execute at all if there's a server error. | 122 » // may not execute at all if there was a server error. |
111 // | 123 // |
112 » // NOTE: Implementations and filters are guaranteed that len(keys) == | 124 » // NOTE: Implementations and filters are guaranteed that: |
113 » // len(vals), that keys are all Valid, and in the correct namespace. | 125 » // - len(keys) > 0 |
114 » // Additionally, vals are guaranteed to be PropertyMaps already. Callbac
k | 126 » // - len(keys) == len(vals) |
115 » // may be nil. | 127 » // - all keys are Valid and in the current namespace |
116 » PutMulti(keys []Key, vals []PropertyLoadSaver, cb PutMultiCB) error | 128 » // - cb is not nil |
| 129 » PutMulti(keys []Key, vals []PropertyMap, cb PutMultiCB) error |
117 | 130 |
118 // DeleteMulti removes items from the datastore. | 131 // DeleteMulti removes items from the datastore. |
119 // | 132 // |
120 // Callback execues once per key, in the order of keys. Callback may not | 133 // Callback execues once per key, in the order of keys. Callback may not |
121 // execute at all if there's a server error. | 134 // execute at all if there's a server error. |
122 // | 135 // |
123 » // NOTE: Implementations and filters are guaranteed that keys are all Va
lid | 136 » // NOTE: Implementations and filters are guaranteed that |
124 » // and Complete, and in the correct namespace, and are not 'special'. | 137 » // - len(keys) > 0 |
125 » // Callback may be nil. | 138 » // - all keys are Valid, !Incomplete, and in the current namespace |
| 139 » // - none keys of the keys are 'special' (use a kind prefixed with '__
') |
| 140 » // - cb is not nil |
126 DeleteMulti(keys []Key, cb DeleteMultiCB) error | 141 DeleteMulti(keys []Key, cb DeleteMultiCB) error |
127 } | 142 } |
OLD | NEW |