Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Commit 0ff2b68

Browse files
authored
1 parent 1f9d550 commit 0ff2b68

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

leveldown.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ function SubDown (db, prefix, opts) {
123123
// Inherit manifest from parent db
124124
...manifest,
125125

126+
// We support this on the levelup interface, but not on the
127+
// abstract-leveldown interface.
128+
deferredOpen: false,
129+
126130
// Disable unsupported features
127-
getMany: false,
128131
keyIterator: false,
129132
valueIterator: false,
130133
iteratorNextv: false,
@@ -144,13 +147,12 @@ SubDown.prototype.type = 'subleveldown'
144147

145148
// TODO: remove _open() once abstract-leveldown supports deferredOpen,
146149
// because that means we can always do operations on this.leveldown.
147-
// Alternatively have the sublevel follow the open state of this.db.
148150
SubDown.prototype._open = function (opts, cb) {
149-
// TODO: make _isOpening public in levelup or add a method like
150-
// ready(cb) which waits for - but does not initiate - a state change.
151+
// TODO: start using db.status (added to levelup recently) in a next major.
151152
const m = typeof this.db.isOpening === 'function' ? 'isOpening' : '_isOpening'
152153

153154
const onopen = () => {
155+
// TODO: start using db.status (added to levelup recently) in a next major.
154156
if (!this.db.isOpen()) return cb(new Error('Parent database is not open'))
155157
if (this.leveldown.status !== 'open') return cb(new Error('Inner database is not open'))
156158

@@ -181,6 +183,12 @@ SubDown.prototype._get = function (key, opts, cb) {
181183
this.leveldown.get(concat(this.prefix, key), opts, cb)
182184
}
183185

186+
SubDown.prototype._getMany = function (keys, opts, cb) {
187+
// maybeError is not necessary here, abstract-leveldown does that
188+
keys = keys.map(key => concat(this.prefix, key))
189+
this.leveldown.getMany(keys, opts, cb)
190+
}
191+
184192
SubDown.prototype._del = function (key, opts, cb) {
185193
if (maybeError(this.leveldown, cb)) return
186194
this.leveldown.del(concat(this.prefix, key), opts, cb)
@@ -235,7 +243,7 @@ function maybeError (leveldown, callback) {
235243
if (leveldown.status !== 'open') {
236244
// Same error message as levelup
237245
// TODO: use require('level-errors').ReadError
238-
nextTick(callback, new Error('Database is not open'))
246+
;(leveldown._nextTick || nextTick)(callback, new Error('Database is not open'))
239247
return true
240248
}
241249

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"test": "test"
1818
},
1919
"dependencies": {
20-
"abstract-leveldown": "^7.1.0",
21-
"encoding-down": "^7.0.0",
20+
"abstract-leveldown": "^7.2.0",
21+
"encoding-down": "^7.1.0",
2222
"inherits": "^2.0.3",
2323
"level-option-wrap": "^1.1.0",
24-
"levelup": "^5.0.1",
24+
"levelup": "^5.1.0",
2525
"reachdown": "^1.1.0"
2626
},
2727
"devDependencies": {
@@ -33,7 +33,7 @@
3333
"hallmark": "^3.1.0",
3434
"level-community": "^3.0.0",
3535
"level-concat-iterator": "^3.0.0",
36-
"memdown": "^6.0.0",
36+
"memdown": "^6.1.0",
3737
"nyc": "^15.1.0",
3838
"standard": "^16.0.3",
3939
"tape": "^5.0.1"

test/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ function runSuite (factory) {
2525
createIfMissing: false,
2626
errorIfExists: false,
2727

28-
// Opt-in to new clear() tests
29-
clear: true
28+
// Opt-in to new tests
29+
clear: true,
30+
getMany: true
3031
})
3132
}
3233

@@ -56,6 +57,7 @@ runSuite(function factory () {
5657
down.supports.deferredOpen = true
5758
down.isOpen = function () { return this.status === 'open' }
5859
down.isOpening = function () { return this.status === 'opening' }
60+
down._isOperational = () => this.status === 'opening'
5961
down.once = emitter.once.bind(emitter)
6062
down.open(function (err) {
6163
if (err) throw err
@@ -78,10 +80,12 @@ suite({
7880
createIfMissing: false,
7981
errorIfExists: false,
8082

81-
// Opt-in to new clear() tests
83+
// Opt-in to new tests
8284
clear: true,
85+
getMany: true,
8386

8487
// Adapt for levelup
88+
deferredOpen: true,
8589
promises: true,
8690
status: false,
8791
serialize: false,

0 commit comments

Comments
 (0)