You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 9, 2021. It is now read-only.
* refactor: async iterators
Here's a proposal for the datastore interface that uses async/await and async iterators.
See ipfs/js-ipfs#1670 for context.
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
* chore: use node.js 10 in CI
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
* chore: appease linter
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
* fix: remove unnecessary assertion
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
The key scheme is inspired by file systems and Google App Engine key model. Keys are meant to be unique across a system. They are typical hierarchical, incorporating more and more specific namespaces. Thus keys can be deemed 'children' or 'ancestors' of other keys:
101
+
The key scheme is inspired by file systems and Google App Engine key model. Keys are meant to be unique across a system. They are typically hierarchical, incorporating more and more specific namespaces. Thus keys can be deemed 'children' or 'ancestors' of other keys:
103
102
104
103
-`new Key('/Comedy')`
105
104
-`new Key('/Comedy/MontyPython')`
106
105
107
-
Also, every namespace can be parametrized to embed relevant object information. For example, the Key `name` (most specific namespace) could include the object type:
106
+
Also, every namespace can be parameterized to embed relevant object information. For example, the Key `name` (most specific namespace) could include the object type:
@@ -117,90 +116,65 @@ Also, every namespace can be parametrized to embed relevant object information.
117
116
118
117
These methods will be present on every datastore. `Key` always means an instance of the above mentioned Key type. Every datastore is generic over the `Value` type, though currently all backing implementations are implemented only for [`Buffer`](https://nodejs.org/docs/latest/api/buffer.html).
Search the store for some values. Returns a [pull-stream](https://pull-stream.github.io/) with each item being a `Value`.
169
+
Search the store for some values. Returns an [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) with each item being a `Value`.
192
170
193
171
```js
194
172
// retrieve __all__ values from the store
195
-
pull(
196
-
store.query({}),
197
-
pull.collect((err, list) => {
198
-
if (err) {
199
-
console.error(err)
200
-
}
201
-
console.log('ALL THE VALUES', list)
202
-
})
203
-
)
173
+
let list = []
174
+
forawait (constvalueofstore.query({})) {
175
+
list.push(value)
176
+
}
177
+
console.log('ALL THE VALUES', list)
204
178
```
205
179
206
180
#### `Query`
@@ -210,9 +184,9 @@ Object in the form with the following optional properties
210
184
-`prefix: string` (optional) - only return values where the key starts with this prefix
211
185
-`filters: Array<Filter<Value>>` (optional) - filter the results according to the these functions
212
186
-`orders: Array<Order<Value>>` (optional) - order the results according to these functions
213
-
-`limit: number` (optional) - only return this many records
214
-
-`offset: number` (optional) - skip this many records at the beginning
215
-
-`keysOnly: bool` (optional) - Only return keys, no values.
187
+
-`limit: Number` (optional) - only return this many records
188
+
-`offset: Number` (optional) - skip this many records at the beginning
189
+
-`keysOnly: Boolean` (optional) - Only return keys, no values.
216
190
217
191
### `batch()`
218
192
@@ -225,13 +199,8 @@ for (let i = 0; i < 100; i++) {
225
199
b.put(newKey(`hello${i}`), newBuffer(`hello world ${i}`))
226
200
}
227
201
228
-
b.commit((err) => {
229
-
if (err) {
230
-
throw err
231
-
}
232
-
console.log('put 100 values')
233
-
})
234
-
202
+
awaitb.commit()
203
+
console.log('put 100 values')
235
204
```
236
205
237
206
#### `put(key, value)`
@@ -247,21 +216,15 @@ Queue a put operation to the store.
247
216
248
217
Queue a delete operation to the store.
249
218
250
-
#### `commit(callback)`
251
-
252
-
-`callback: function(Error)`
219
+
#### `commit()` -> `Promise`
253
220
254
221
Write all queued operations to the underyling store. The batch object should not be used after calling this.
255
222
256
-
### `open(callback)`
257
-
258
-
-`callback: function(Error)`
223
+
### `open()` -> `Promise`
259
224
260
225
Opens the datastore, this is only needed if the store was closed before, otherwise this is taken care of by the constructor.
261
226
262
-
### `close(callback)`
263
-
264
-
-`callback: function(Error)`
227
+
### `close()` -> `Promise`
265
228
266
229
Close the datastore, this should always be called to ensure resources are cleaned up.
0 commit comments