Skip to content

Commit 2af4d29

Browse files
authored
Add docs for private _has() and _hasMany() (#115)
Follow-up to #96. I forgot to document the private API. Category: addition
1 parent c35ab16 commit 2af4d29

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,29 @@ Snapshot behavior of `db._getMany()` must be the same as described for `db._get(
15171517

15181518
The default `_getMany()` returns a promise for an array of values that is equal in length to `keys` and is filled with `undefined`. It must be overridden.
15191519

1520+
### `db._has(key, options)`
1521+
1522+
Check if the database has an entry with the given `key`. The `options` object will always have the following properties: `keyEncoding`. Must return a promise. If an error occurs, reject the promise. Otherwise resolve the promise with a boolean.
1523+
1524+
The default `_has()` throws a [`LEVEL_NOT_SUPPORTED`](#level_not_supported) error. It is an optional feature at the moment. If implemented then `_hasMany()` must also be implemented. Set `manifest.has` to `true` in order to enable tests:
1525+
1526+
```js
1527+
class ExampleLevel extends AbstractLevel {
1528+
constructor (/* ... */) {
1529+
const manifest = {
1530+
has: true,
1531+
// ...
1532+
}
1533+
1534+
super(manifest, options)
1535+
}
1536+
}
1537+
```
1538+
1539+
### `db._hasMany(keys, options)`
1540+
1541+
Check if the database has entries with the given keys. The `keys` argument is guaranteed to be an array. The `options` object will always have the following properties: `keyEncoding`. Must return a promise. If an error occurs, reject the promise. Otherwise resolve the promise with an array of booleans.
1542+
15201543
### `db._put(key, value, options)`
15211544

15221545
Add a new entry or overwrite an existing entry. The `options` object will always have the following properties: `keyEncoding` and `valueEncoding`. Must return a promise. If an error occurs, reject the promise. Otherwise resolve the promise, without an argument.

0 commit comments

Comments
 (0)