Skip to content

Commit

Permalink
test for remote batch operations
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Apr 16, 2013
1 parent 0435593 commit 40dff89
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/nested-batch.js
@@ -0,0 +1,33 @@
var getDb = require('./util').getDb
var test = require('tap').test
var sublevel = require('level-sublevel')

test('async', function (t) {
t.plan(2)

getDb(function (db) {
sublevel(db)
db.sublevel('foo')
db.sublevel('bar')
},
function (db, dispose) {
db.sublevel('foo').batch([
{key:'f', value:'1', type: 'put'},
{key:'b', value:'2', type: 'put', prefix: db.sublevel('bar').prefix()}

This comment has been minimized.

Copy link
@juliangruber

juliangruber Apr 21, 2013

why's that necessary?

This comment has been minimized.

Copy link
@dominictarr

dominictarr Apr 21, 2013

Author Owner

it's possible to do a batch across multiple sublevels,
notice that it's db.sublevel('foo').batch([{.... prefix: db.sublevel('bar').prefix()}])

this is an essential feature, necessary to for things like triggers, and indexes.

This comment has been minimized.

Copy link
@juliangruber

juliangruber Apr 21, 2013

what about

{key:'b', value:'2', type: 'put', sublevel: db.sublevel('bar')}

Less leaky IMO

This comment has been minimized.

Copy link
@dominictarr

dominictarr Apr 22, 2013

Author Owner

Needs to be a string so that it can be sent over the wire...
Am contemplating adding code to the manifest, (manifest.js instead).
Which could be used to handle cases like this...

Which can handle things like this, but making this compromise got it out the door.

],
function (err) {
if (err) throw err
db.sublevel('foo').get('f', function (err, value) {
if (err) throw err
t.equal(value, '1')
console.log('done1', value)
db.sublevel('bar').get('b', function (err, value) {
if (err) throw err
t.equal(value, '2')
console.log('done2', value)
dispose()
})
})
})
})
})

0 comments on commit 40dff89

Please sign in to comment.