browser: ldb.
This commit is contained in:
parent
90c4f3dcf6
commit
a03465632a
@ -1,11 +1,12 @@
|
|||||||
var level = require('level-js');
|
var level = require('level-js');
|
||||||
|
|
||||||
function DB(file) {
|
function DB(location) {
|
||||||
this.level = new level(file);
|
this.level = new level(location);
|
||||||
this.bufferKeys = false;
|
this.bufferKeys = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DB.prototype.open = function open(options, callback) {
|
DB.prototype.open = function open(options, callback) {
|
||||||
|
this.bufferKeys = options.bufferKeys;
|
||||||
this.level.open(options, callback);
|
this.level.open(options, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -38,27 +39,24 @@ DB.prototype.batch = function batch(ops, options, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
DB.prototype.iterator = function iterator(options) {
|
DB.prototype.iterator = function iterator(options) {
|
||||||
options.keyAsBuffer = false;
|
|
||||||
return new Iterator(this, options);
|
return new Iterator(this, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
DB.prototype.approximateSize = function approximateSize(start, end, callback) {
|
DB.destroy = function destroy(db, callback) {
|
||||||
return this.level.approximateSize(start, end, callback);
|
level.destroy(db, callback);
|
||||||
};
|
|
||||||
|
|
||||||
DB.prototype.getProperty = function getProperty(name) {
|
|
||||||
return this.level.getProperty(name);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function Batch(db) {
|
function Batch(db) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.batch = db.level.batch();
|
this.batch = db.level.batch();
|
||||||
|
this.hasOps = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Batch.prototype.put = function(key, value) {
|
Batch.prototype.put = function(key, value) {
|
||||||
if (this.db.bufferKeys && Buffer.isBuffer(key))
|
if (this.db.bufferKeys && Buffer.isBuffer(key))
|
||||||
key = key.toString('hex');
|
key = key.toString('hex');
|
||||||
this.batch.put(key, value);
|
this.batch.put(key, value);
|
||||||
|
this.hasOps = true;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -66,10 +64,13 @@ Batch.prototype.del = function del(key) {
|
|||||||
if (this.db.bufferKeys && Buffer.isBuffer(key))
|
if (this.db.bufferKeys && Buffer.isBuffer(key))
|
||||||
key = key.toString('hex');
|
key = key.toString('hex');
|
||||||
this.batch.del(key);
|
this.batch.del(key);
|
||||||
|
this.hasOps = true;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
Batch.prototype.write = function write(callback) {
|
Batch.prototype.write = function write(callback) {
|
||||||
|
if (!this.hasOps)
|
||||||
|
return callback();
|
||||||
this.batch.write(callback);
|
this.batch.write(callback);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@ -80,6 +81,17 @@ Batch.prototype.clear = function clear() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function Iterator(db, options) {
|
function Iterator(db, options) {
|
||||||
|
if (db.bufferKeys) {
|
||||||
|
if (Buffer.isBuffer(options.gt))
|
||||||
|
options.gt = options.gt.toString('hex');
|
||||||
|
if (Buffer.isBuffer(options.gte))
|
||||||
|
options.gte = options.gte.toString('hex');
|
||||||
|
if (Buffer.isBuffer(options.lt))
|
||||||
|
options.lt = options.lt.toString('hex');
|
||||||
|
if (Buffer.isBuffer(options.lte))
|
||||||
|
options.lte = options.lte.toString('hex');
|
||||||
|
}
|
||||||
|
options.keyAsBuffer = false;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.iter = db.level.iterator(options);
|
this.iter = db.level.iterator(options);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,9 +40,6 @@ function LowlevelUp(file, options) {
|
|||||||
|
|
||||||
this.db = new options.db(file);
|
this.db = new options.db(file);
|
||||||
|
|
||||||
if (utils.isBrowser)
|
|
||||||
this.db.bufferKeys = options.bufferKeys;
|
|
||||||
|
|
||||||
// Stay as close to the metal as possible.
|
// Stay as close to the metal as possible.
|
||||||
// We want to make calls to C++ directly.
|
// We want to make calls to C++ directly.
|
||||||
while (this.db.db && this.db.db.put && this.db.db !== this.db)
|
while (this.db.db && this.db.db.put && this.db.db !== this.db)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user