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

Commit ae32a1f

Browse files
committed
add forwarding api to fix level-party edge-case
1 parent 3ed11b2 commit ae32a1f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

leveldown.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function Multilevel (path, opts) {
3333
this._encode = lpstream.encode()
3434
this._streaming = null
3535
this._ref = null
36+
this._db = null
3637
}
3738

3839
util.inherits(Multilevel, abstract.AbstractLevelDOWN)
@@ -115,6 +116,10 @@ Multilevel.prototype.createRpcStream = function (opts, proxy) {
115116
}
116117
}
117118

119+
Multilevel.prototype.forward = function (down) {
120+
this._db = down
121+
}
122+
118123
Multilevel.prototype.isFlushed = function () {
119124
return !this._requests.length && !this._iterators.length
120125
}
@@ -141,6 +146,8 @@ Multilevel.prototype._clearRequests = function (closing) {
141146
}
142147

143148
Multilevel.prototype._get = function (key, opts, cb) {
149+
if (this._db) return this._db._get(key, opts, cb)
150+
144151
var req = {
145152
tag: 0,
146153
id: 0,
@@ -154,6 +161,8 @@ Multilevel.prototype._get = function (key, opts, cb) {
154161
}
155162

156163
Multilevel.prototype._put = function (key, value, opts, cb) {
164+
if (this._db) return this._db._put(key, value, opts, cb)
165+
157166
var req = {
158167
tag: 1,
159168
id: 0,
@@ -167,6 +176,8 @@ Multilevel.prototype._put = function (key, value, opts, cb) {
167176
}
168177

169178
Multilevel.prototype._del = function (key, opts, cb) {
179+
if (this._db) return this._db._del(key, opts, cb)
180+
170181
var req = {
171182
tag: 2,
172183
id: 0,
@@ -179,6 +190,8 @@ Multilevel.prototype._del = function (key, opts, cb) {
179190
}
180191

181192
Multilevel.prototype._batch = function (batch, opts, cb) {
193+
if (this._db) return this._db._batch(batch, opts, cb)
194+
182195
var req = {
183196
tag: 3,
184197
id: 0,
@@ -200,6 +213,8 @@ Multilevel.prototype._write = function (req) {
200213
}
201214

202215
Multilevel.prototype._close = function (cb) {
216+
if (this._db) return this._close(cb)
217+
203218
this._clearRequests(true)
204219
if (this._streaming) {
205220
this._streaming.once('close', cb)
@@ -210,6 +225,7 @@ Multilevel.prototype._close = function (cb) {
210225
}
211226

212227
Multilevel.prototype._iterator = function (opts) {
228+
if (this._db) return this._iterator(opts)
213229
return new Iterator(this, opts)
214230
}
215231

0 commit comments

Comments
 (0)