Skip to content

Commit be68717

Browse files
authored
Document manifest, iterator() and clear() (#162)
1 parent 97cb31c commit be68717

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ If you want to use [Promises](#promise-support), you will need a polyfill like [
7777
For options specific to [`leveldown`][leveldown] and [`level-js`][level-js] ("underlying store" from here on out), please see their respective READMEs.
7878

7979
- <a href="#ctor"><code><b>level()</b></code></a>
80+
- <a href="#supports"><code>db.<b>supports</b></code></a>
8081
- <a href="#open"><code>db.<b>open()</b></code></a>
8182
- <a href="#close"><code>db.<b>close()</b></code></a>
8283
- <a href="#put"><code>db.<b>put()</b></code></a>
@@ -89,6 +90,8 @@ For options specific to [`leveldown`][leveldown] and [`level-js`][level-js] ("un
8990
- <a href="#createReadStream"><code>db.<b>createReadStream()</b></code></a>
9091
- <a href="#createKeyStream"><code>db.<b>createKeyStream()</b></code></a>
9192
- <a href="#createValueStream"><code>db.<b>createValueStream()</b></code></a>
93+
- <a href="#iterator"><code>db.<b>iterator()</b></code></a>
94+
- <a href="#clear"><code>db.<b>clear()</b></code></a>
9295

9396
<a name="ctor"></a>
9497

@@ -139,6 +142,22 @@ level('my-db', { createIfMissing: false }, function (err, db) {
139142

140143
Note that `createIfMissing` is an option specific to [`leveldown`][leveldown].
141144

145+
<a name="supports"></a>
146+
147+
### `db.supports`
148+
149+
A read-only [manifest](https://github.com/Level/supports). Not [widely supported yet](https://github.com/Level/community/issues/83). Might be used like so:
150+
151+
```js
152+
if (!db.supports.permanence) {
153+
throw new Error('Persistent storage is required')
154+
}
155+
156+
if (db.supports.bufferKeys && db.supports.promises) {
157+
await db.put(Buffer.from('key'), 'value')
158+
}
159+
```
160+
142161
<a name="open"></a>
143162

144163
### `db.open([callback])`
@@ -393,6 +412,29 @@ db.createReadStream({ keys: false, values: true })
393412
})
394413
```
395414

415+
<a name="iterator"></a>
416+
417+
### `db.iterator([options])`
418+
419+
Returns an [`abstract-leveldown` iterator](https://github.com/Level/abstract-leveldown/#iterator), which is what powers the readable streams above. Options are the same as the range options of <a href="#createReadStream"><code>createReadStream</code></a> and are passed to the underlying store.
420+
421+
<a name="clear"></a>
422+
423+
### `db.clear([options][, callback])`
424+
425+
**This method is experimental. Not all underlying stores support it yet. Consult [Level/community#79](https://github.com/Level/community/issues/79) to find out if your (combination of) dependencies support `db.clear()`.**
426+
427+
Delete all entries or a range. Not guaranteed to be atomic. Accepts the following range options (with the same rules as on iterators):
428+
429+
- `gt` (greater than), `gte` (greater than or equal) define the lower bound of the range to be deleted. Only entries where the key is greater than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the entries deleted will be the same.
430+
- `lt` (less than), `lte` (less than or equal) define the higher bound of the range to be deleted. Only entries where the key is less than (or equal to) this option will be included in the range. When `reverse=true` the order will be reversed, but the entries deleted will be the same.
431+
- `reverse` _(boolean, default: `false`)_: delete entries in reverse order. Only effective in combination with `limit`, to remove the last N records.
432+
- `limit` _(number, default: `-1`)_: limit the number of entries to be deleted. This number represents a _maximum_ number of entries and may not be reached if you get to the end of the range first. A value of `-1` means there is no limit. When `reverse=true` the entries with the highest keys will be deleted instead of the lowest keys.
433+
434+
If no options are provided, all entries will be deleted. The `callback` function will be called with no arguments if the operation was successful or with an `WriteError` if it failed for any reason.
435+
436+
If no callback is passed, a promise is returned.
437+
396438
## Promise Support
397439

398440
`level(up)` ships with native `Promise` support out of the box.
@@ -404,6 +446,7 @@ Each function taking a callback also can be used as a promise, if the callback i
404446
- `db.del(key[, options])`
405447
- `db.batch(ops[, options])`
406448
- `db.batch().write()`
449+
- `db.clear(options)`
407450

408451
The only exception is the `level` constructor itself, which if no callback is passed will lazily open the underlying store in the background.
409452

0 commit comments

Comments
 (0)