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

Commit fb1c5a4

Browse files
committed
1 parent e75a500 commit fb1c5a4

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

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

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)