This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking: only defer operations while db is opening
In other states (besides 'open') a 'Database is not open' error is now thrown. This reduces the scope of `deferred-leveldown` to what's strictly needed in `levelup` and aligns behavior. In addition, override public methods of `abstract-leveldown` instead of private methods. This has one downside: they need to do the same callback to promise conversion that `abstract-leveldown` does. The upside is that operation callbacks are not called before the db has finished opening, including in cases where `abstract-leveldown` has a fast-path, like on `db.batch([])` which because the array is empty bypasses `_batch()`. Closes #91 Closes #90
- Loading branch information
Showing
6 changed files
with
657 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const AbstractChainedBatch = require('abstract-leveldown').AbstractChainedBatch | ||
const inherits = require('inherits') | ||
const kOperations = Symbol('operations') | ||
|
||
function DeferredChainedBatch (db) { | ||
AbstractChainedBatch.call(this, db) | ||
this[kOperations] = [] | ||
} | ||
|
||
inherits(DeferredChainedBatch, AbstractChainedBatch) | ||
|
||
DeferredChainedBatch.prototype._put = function (key, value, options) { | ||
this[kOperations].push({ ...options, type: 'put', key, value }) | ||
} | ||
|
||
DeferredChainedBatch.prototype._del = function (key, options) { | ||
this[kOperations].push({ ...options, type: 'del', key }) | ||
} | ||
|
||
DeferredChainedBatch.prototype._clear = function () { | ||
this[kOperations] = [] | ||
} | ||
|
||
DeferredChainedBatch.prototype._write = function (options, callback) { | ||
// AbstractChainedBatch would call _batch(), we call batch() | ||
this.db.batch(this[kOperations], options, callback) | ||
} | ||
|
||
module.exports = DeferredChainedBatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.