Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ const db = new RaveLevel('./db')

### `db = new RaveLevel(location[, options])`

The `location` argument is the same as in [`classic-level`](https://github.com/Level/classic-level), making `rave-level` a drop-in replacement for when you need to read and write to the given `location` from multiple processes simultaneously. However, the `options` are different and limited because not every `RaveLevel` instance has direct access to the underlying LevelDB database. The `options` object may contain:
The `location` argument is the same as in [`classic-level`](https://github.com/Level/classic-level), making `rave-level` a drop-in replacement for when you need to read and write to the given `location` from multiple processes simultaneously. The `options` object may contain:

- `keyEncoding` (string or object, default `'utf8'`): [encoding](https://github.com/Level/abstract-level#encodings) to use for keys
- `valueEncoding` (string or object, default `'utf8'`): encoding to use for values
- `retry` (boolean, default `true`): if true, operations are retried upon connecting to a new leader. This disables [snapshot guarantees](https://github.com/Level/abstract-level#iterator) because retries may implicitly use new snapshots. If false, operations are aborted upon disconnect, which means to yield an error on e.g. `db.get()`.

Additionnaly, all the options accepted by [`classic-level`](https://github.com/Level/classic-level#db--new-classiclevellocation-options) are also accepted by `rave-level` but will only have an effect for the leader instance.

The `RaveLevel` class extends `AbstractLevel` and thus follows the public API of [`abstract-level`](https://github.com/Level/abstract-level). As such, the rest of the API is documented in `abstract-level`. The database opens itself but (unlike other `abstract-level` implementations) cannot be re-opened once `db.close()` has been called. Calling `db.open()` would then yield a [`LEVEL_NOT_SUPPORTED`](https://github.com/Level/abstract-level#errors) error.

### Events
Expand Down
5 changes: 3 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AbstractLevel, AbstractDatabaseOptions } from 'abstract-level'
import { AbstractLevel } from 'abstract-level'
import { DatabaseOptions as ClassicLevelDatabaseOptions } from 'classic-level'

/**
* Use a [LevelDB](https://github.com/google/leveldb) database from multiple processes
Expand Down Expand Up @@ -26,7 +27,7 @@ export class RaveLevel<KDefault = string, VDefault = string>
* Options for the {@link RaveLevel} constructor.
*/
declare interface DatabaseOptions<K, V> extends
Omit<AbstractDatabaseOptions<K, V>, 'createIfMissing' | 'errorIfExists'> {
ClassicLevelDatabaseOptions<K, V> {
/**
* If true, operations are retried upon connecting to a new leader. If false,
* operations are aborted upon disconnect, which means to yield an error on e.g.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports.RaveLevel = class RaveLevel extends ManyLevelGuest {

this[kLocation] = path.resolve(location)
this[kSocketPath] = socketPath(this[kLocation])
this[kOptions] = { keyEncoding, valueEncoding }
this[kOptions] = options
this[kConnect] = this[kConnect].bind(this)
this[kDestroy] = this[kDestroy].bind(this)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rave-level",
"version": "1.0.0",
"version": "1.0.1",
"description": "Use a LevelDB database from multiple processes with seamless failover",
"license": "MIT",
"main": "index.js",
Expand Down