Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

level-sublevel

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-sublevel - npm Package Compare versions

Comparing version 5.1.1 to 5.2.0

batch.js

5

index.js
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) {

2

package.json
{
"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()
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc