@@ -123,8 +123,11 @@ function SubDown (db, prefix, opts) {
123
123
// Inherit manifest from parent db
124
124
...manifest ,
125
125
126
+ // We support this on the levelup interface, but not on the
127
+ // abstract-leveldown interface.
128
+ deferredOpen : false ,
129
+
126
130
// Disable unsupported features
127
- getMany : false ,
128
131
keyIterator : false ,
129
132
valueIterator : false ,
130
133
iteratorNextv : false ,
@@ -144,13 +147,12 @@ SubDown.prototype.type = 'subleveldown'
144
147
145
148
// TODO: remove _open() once abstract-leveldown supports deferredOpen,
146
149
// because that means we can always do operations on this.leveldown.
147
- // Alternatively have the sublevel follow the open state of this.db.
148
150
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.
151
152
const m = typeof this . db . isOpening === 'function' ? 'isOpening' : '_isOpening'
152
153
153
154
const onopen = ( ) => {
155
+ // TODO: start using db.status (added to levelup recently) in a next major.
154
156
if ( ! this . db . isOpen ( ) ) return cb ( new Error ( 'Parent database is not open' ) )
155
157
if ( this . leveldown . status !== 'open' ) return cb ( new Error ( 'Inner database is not open' ) )
156
158
@@ -181,6 +183,12 @@ SubDown.prototype._get = function (key, opts, cb) {
181
183
this . leveldown . get ( concat ( this . prefix , key ) , opts , cb )
182
184
}
183
185
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
+
184
192
SubDown . prototype . _del = function ( key , opts , cb ) {
185
193
if ( maybeError ( this . leveldown , cb ) ) return
186
194
this . leveldown . del ( concat ( this . prefix , key ) , opts , cb )
@@ -235,7 +243,7 @@ function maybeError (leveldown, callback) {
235
243
if ( leveldown . status !== 'open' ) {
236
244
// Same error message as levelup
237
245
// 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' ) )
239
247
return true
240
248
}
241
249
0 commit comments