Skip to content

Instantly share code, notes, and snippets.

@sergioramos
Last active December 23, 2015 19:21
Show Gist options
  • Save sergioramos/4578979 to your computer and use it in GitHub Desktop.
Save sergioramos/4578979 to your computer and use it in GitHub Desktop.
var cursor = require('levelup-cursor')
/************************************** A *************************************/
db.readStream().pipe(cursor.each(function (data) {
assert.equal(data, {
value: 'value',
key: 'key'
})
}, function (e) {
assert.equal(e, null)
}))
db.readStream().pipe(cursor.all(function (e, data) {
assert.equal(e, null)
assert.equal(data, [{
value: 'value',
key: 'key'
}, {
value: 'value2',
key: 'key2'
}])
}))
/************************************** B *************************************/
db.readStream().pipe(cursor.each(function (data) {
assert.equal(data, {
value: 'value',
key: 'key'
})
}, function (e) {
assert.equal(e, null)
}))
db.readStream().pipe(cursor.all(function (e, data) {
assert.equal(e, null)
assert.equal(data, {
'key': 'value',
'key2': 'value2'
})
}))
/************************************** C *************************************/
db.readStream().pipe(cursor.each(function (data) {
assert.equal(data, {
'key': 'value'
})
}, function (e) {
assert.equal(e, null)
}))
db.readStream().pipe(cursor.all(function (e, data) {
assert.equal(e, null)
assert.equal(data, {
'key': 'value',
'key2': 'value2'
})
}))
@sergioramos
Copy link
Author

regarding cursor API, which one is the best?

@rvagg
Copy link

rvagg commented Jan 20, 2013

I personally prefer the explicitness of A but some of the feedback I've got from the batch() API is the it's too verbose for some people.

@sergioramos
Copy link
Author

@rvagg thanks for the response.

While using the API I found the explicitness useful sometimes, and too verbose other times. It depends on what I need :/ Thats why I'm in doubt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment