level-sublevel
Advanced tools
Comparing version 5.1.1 to 5.2.0
var EventEmitter = require('events').EventEmitter | ||
var next = process.nextTick | ||
var SubDb = require('./sub') | ||
var Batch = require('./batch') | ||
var fixRange = require('level-fix-range') | ||
@@ -72,7 +73,7 @@ | ||
db.createValueStream = safeRange(db.createValueStream) | ||
var batch = db.batch | ||
db.batch = function (changes, opts, cb) { | ||
if(!Array.isArray(changes)) | ||
throw new Error('batch must be passed an Array') | ||
return new Batch(db) | ||
changes.forEach(function (e) { | ||
@@ -79,0 +80,0 @@ if(e.prefix) { |
{ | ||
"name": "level-sublevel", | ||
"description": "partition levelup databases", | ||
"version": "5.1.1", | ||
"version": "5.2.0", | ||
"homepage": "https://github.com/dominictarr/level-sublevel", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -16,3 +16,3 @@ # level-sublevel | ||
This is module is working well, but may change in the future as it's use is futher explored. | ||
This is module is working well, but may change in the future as its use is futher explored. | ||
@@ -48,3 +48,3 @@ ## Example | ||
Records added via hooks will be atomically with the triggering change. | ||
Records added via hooks will be atomically inserted with the triggering change. | ||
@@ -51,0 +51,0 @@ ### Hooks Example |
@@ -6,2 +6,3 @@ var EventEmitter = require('events').EventEmitter | ||
var xtend = require('xtend') | ||
var Batch = require('./batch') | ||
@@ -83,3 +84,3 @@ inherits(SubDB, EventEmitter) | ||
if(!Array.isArray(changes)) | ||
throw new Error('batch must be passed an Array') | ||
return new Batch(this) | ||
var self = this, | ||
@@ -86,0 +87,0 @@ res = this._getOptsAndCb(opts, cb) |
@@ -12,3 +12,3 @@ var test = require('tape') | ||
} | ||
db.createReadStream({end: '\xff\xff'}) | ||
@@ -146,1 +146,151 @@ .on('data', function (ch) { | ||
test('sublevel - batch - chained', function (t) { | ||
var base = sl('test-sublevel5') | ||
var a = base.sublevel('A') | ||
var b = base.sublevel('B') | ||
var sum = 0 | ||
a.batch() | ||
.put('a', 1) | ||
.put('b', 2) | ||
.put('c', 3) | ||
.put('d', 4) | ||
.put('e', 5) | ||
.write(function (err) { | ||
all(a, function (err, obj) { | ||
t.notOk(err) | ||
var keys = Object.keys(obj).join('') | ||
for(var k in obj) { | ||
sum += Number(obj[k]) | ||
} | ||
t.equal(keys, 'abcde') | ||
t.equal(sum, 15) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
test('sublevel - prefixed batches - chained', function (t) { | ||
var base = sl('test-sublevel6') | ||
var a = base.sublevel('A') | ||
var b = base.sublevel('B') | ||
base.batch() | ||
.put('a', 1) | ||
.put('b', 2, {prefix: b}) | ||
.put('c', 3) | ||
.put('d', 4, {prefix: a}) | ||
.put('e', 5, {prefix: base}) | ||
.write(function (err) { | ||
all(base, function (_, obj) { | ||
t.deepEqual(obj, { | ||
'a': '1', | ||
'c': '3', | ||
'e': '5', | ||
'~A~d': '4', | ||
'~B~b': '2' | ||
}) | ||
console.log(obj) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
test('sublevel - prefixed batches on subsection - chained', function (t) { | ||
var base = sl('test-sublevel7') | ||
var a = base.sublevel('A') | ||
var b = base.sublevel('B') | ||
a.batch() | ||
.put('a', 1, {prefix: base}) | ||
.put('b', 2, {prefix: b}) | ||
.put('c', 3, {prefix: base}) | ||
.put('d', 4) | ||
.put('e', 5, {prefix: base}) | ||
.write(function (err) { | ||
all(base, function (_, obj) { | ||
t.deepEqual(obj, { | ||
'a': '1', | ||
'c': '3', | ||
'e': '5', | ||
'~A~d': '4', | ||
'~B~b': '2' | ||
}) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
test('sublevel - prefixed batches on subsection - strings - chained', function (t) { | ||
var base = sl('test-sublevel8') | ||
var a = base.sublevel('A') | ||
var b = base.sublevel('B') | ||
var b_c = b.sublevel('C') | ||
base.batch() | ||
.put('a', 1) | ||
.put('b', 2, {prefix: b.prefix()}) | ||
.put('c', 3) | ||
.put('d', 4, {prefix: a.prefix()}) | ||
.put('e', 5) | ||
.put('f', 6, {prefix: b_c.prefix()}) | ||
.write(function (err) { | ||
all(base, function (_, obj) { | ||
t.deepEqual(obj, { | ||
'a': '1', | ||
'c': '3', | ||
'e': '5', | ||
'~A~d': '4', | ||
'~B~b': '2', | ||
'~B~~C~f': '6' | ||
}) | ||
console.log(obj) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
test('sublevel - delete - chained', function(t) { | ||
var base = sl('test-sublevel9') | ||
var a = base.sublevel('A') | ||
var b = base.sublevel('B') | ||
var sum = 0 | ||
a.batch() | ||
.put('a', 1) | ||
.put('b', 2) | ||
.put('c', 3) | ||
.put('d', 4) | ||
.put('e', 5) | ||
.write() | ||
a.batch() | ||
.del('c') | ||
.del('e') | ||
.write(function (err) { | ||
all(a, function (err, obj) { | ||
t.notOk(err) | ||
var keys = Object.keys(obj).join('') | ||
for(var k in obj) { | ||
sum += Number(obj[k]) | ||
} | ||
t.equal(keys, 'abd') | ||
t.equal(sum, 7) | ||
t.end() | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52750
31
1580
1