@@ -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.
148150SubDown . 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+
184192SubDown . 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
0 commit comments