Update to abstract-leveldown 4 and levelup 2#7
Conversation
ralphtheninja
left a comment
There was a problem hiding this comment.
Awesome work @finnp ! Maybe also update .travis.yml to use:
- 9
- 8
- 6
- 4
| require('abstract-leveldown/abstract/close-test').close(down, test, testCommon) | ||
| require('abstract-leveldown/abstract/iterator-test').all(down, test, testCommon) | ||
| require('abstract-leveldown/abstract/ranges-test').all(down, test, testCommon) | ||
| require('abstract-leveldown/abstract/iterator-range-test').all(down, test, testCommon) |
There was a problem hiding this comment.
@finnp Did you have any help of the upgrade guide in abstract-leveldown?
There was a problem hiding this comment.
Yes, I had a look at it, that was quite helpful.
There was a problem hiding this comment.
That's awesome to hear! It paid off :)
|
Hmm, this would break encodings (for which var sub = require('subleveldown')
var level = require('level')
var db = level('db')
var subdb = sub(db, 'test', { valueEncoding: 'json' })But wrapping var sub = require('subleveldown')
var levelup = require('levelup')
var leveldown = require('leveldown')
var db = levelup(leveldown('db'))
var subdb = sub(db, 'test', { valueEncoding: 'json' }) |
Yes, you are right. We should add tests for it to |
| } | ||
|
|
||
| return levelup(opts) | ||
| return levelup(subdown(db, prefix, opts), opts) |
There was a problem hiding this comment.
@vweevers What if we did levelup(encoding(subdown(db, prefix, opts)), opts) here instead?
There was a problem hiding this comment.
Should work, yeah, with one addition: also pass opts to encoding().
There was a problem hiding this comment.
What happens with deferred-leveldown though? Wouldn't every (sub)db be wrapped needlessly?
There was a problem hiding this comment.
Hmm, not following you. That's already the case?
There was a problem hiding this comment.
That's already the case?
It is? OK, then never mind, we can optimize that later if we want
There was a problem hiding this comment.
Aye, so each levelup has its own deferred-leveldown and subleveldown just returns a new levelup so nothing has changed there.
But I agree, it's a bit overhead maybe. Not sure what we can do about it since it's part of levelup.
There was a problem hiding this comment.
@vweevers What if we did levelup(encoding(subdown(db, prefix, opts)), opts) here instead?
Commenting on my own comment 😄
This is exactly what level does, so we could probably do:
return level(subdown(db, prefix, opts), opts)There was a problem hiding this comment.
Scratch my last comment. I meant using level-packager which wraps with levelup and encoding-down.
There was a problem hiding this comment.
This hurts my brain :)
You're not alone :)
|
Just hit this issue today, passing a level@3 to current subleveldown and it tries to double decode json |
|
Is this ready for review? |
|
@mafintosh the missing thing here is the handling of encodings. The suggestion made by @ralphtheninja could work - see #7 (comment). We need unit tests to complete it. |
|
What if we change the API of this to just export a And thinking about: Wouldn't it be generally be simpler to just have a module that takes a |
It does already export this, you can This should work in userland: var sub = require('subleveldown')
var levelup = require('levelup')
var encoding = require('encoding-down')
var leveldown = require('leveldown')
var db = levelup(encoding(leveldown('db')))
var subdb = sub(db, 'test', { valueEncoding: 'json' })I didn't test it though.
Perhaps, but that's something for a new module, to be discussed elsewhere. It doesn't fit |
@emilbayes Good finding. This should be properly documented in e.g. |
|
@finnp Thanks for your work on this! Will break it apart into smaller changes. Hope you don't mind :) |
|
|
Hey,
I updated the dependencies and change the implementation to pass the tests for the latest
abstract-leveldown.Also: How do you feel about maybe moving this to the level org?
There's a discussion going on at Level/community#14