proxy a leveldb reference to swap instances transparently
proxy a leveldb reference so you can swap backend instances on the fly
This is useful for modules that need to switch out references transparently, like automatically upgrading an ordinary vanilla reference into a multilevel handle. You could probably also use this module to implement even crazier things, like a transparent hash ring.
In this example, we'll create 2 db handles proxied by the level-proxy handle
b. The handles will swap into being the active handle every 3
var level = ;var levelSwap = ;var a = ;var b = ;var db = ;var n = 0;;;var index = 0;;
$ node example/swap.jsa.x= 2b.x= 22a.x= 6b.x= 22a.x= 10b.x= 22a.x= 10b.x= 14a.x= 10b.x= 18^C
You can proxy streaming methods with buffering too:
var level = ;var levelProxy = ;var a = ;var b = ;a;b;var db = ;;var index = 0;;
$ node example/stream.js[ 'x', 'y', 'z' ][ 'x', 'y', 'z' ][ 'x', 'y', 'z' ][ 'x', 'y', 'z' ][ 'x', 'y', 'z' ][ 'a', 'b', 'c' ][ 'a', 'b', 'c' ][ 'a', 'b', 'c' ][ 'x', 'y', 'z' ][ 'x', 'y', 'z' ][ 'x', 'y', 'z' ][ 'a', 'b', 'c' ]^C
var levelProxy = ;
Create a new proxied database handle
db, including events. All the leveldown
methods are available on the
db instance and all method calls will be queued
when a database handle isn't yet available so you can start using the handle
You can optionally give an initial
initDb handle to use, which is the same as
db.swap(initDb) after creating an instance.
Swap out the db's internal proxy for a leveldb handle
Any buffered method calls that have queued up will fire on
newDb on the same
This event triggers a
'swap' event with the
All of these methods behave the same as with an ordinary level db handle.
leveldown methods such as
db.db.iterator() are also proxied.
With npm do:
npm install level-proxy