Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to abstract-leveldown 4 and levelup 2 #7

Closed
wants to merge 2 commits into from

Conversation

finnp
Copy link
Member

@finnp finnp commented Feb 11, 2018

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

Copy link
Member

@ralphtheninja ralphtheninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @finnp ! Maybe also update .travis.yml to use:

  • 9
  • 8
  • 6
  • 4

require('abstract-leveldown/abstract/batch-test').all(down, test, testCommon)
require('abstract-leveldown/abstract/chained-batch-test').all(down, test, testCommon)
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@finnp Did you have any help of the upgrade guide in abstract-leveldown?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I had a look at it, that was quite helpful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's awesome to hear! It paid off :)

@vweevers
Copy link
Member

Hmm, this would break encodings (for which subleveldown has no tests) as subleveldown expects levelup to handle that but it no longer does. I think wrapping level would work:

var sub = require('subleveldown')
var level = require('level')

var db = level('db')
var subdb = sub(db, 'test', { valueEncoding: 'json' })

But wrapping levelup would not:

var sub = require('subleveldown')
var levelup = require('levelup')
var leveldown = require('leveldown')

var db = levelup(leveldown('db'))
var subdb = sub(db, 'test', { valueEncoding: 'json' })

@ralphtheninja
Copy link
Member

Hmm, this would break encodings (for which subleveldown has no tests) as subleveldown expects levelup to handle that but it no longer does. I think wrapping level would work:

Yes, you are right. We should add tests for it to subleveldown as well.

}

return levelup(opts)
return levelup(subdown(db, prefix, opts), opts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vweevers What if we did levelup(encoding(subdown(db, prefix, opts)), opts) here instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should work, yeah, with one addition: also pass opts to encoding().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens with deferred-leveldown though? Wouldn't every (sub)db be wrapped needlessly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not following you. That's already the case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's already the case?

It is? OK, then never mind, we can optimize that later if we want

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch my last comment. I meant using level-packager which wraps with levelup and encoding-down.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hurts my brain :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hurts my brain :)

You're not alone :)

@emilbayes
Copy link

Just hit this issue today, passing a level@3 to current subleveldown and it tries to double decode json

@mafintosh
Copy link
Member

Is this ready for review?

@vweevers
Copy link
Member

@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.

@finnp
Copy link
Member Author

finnp commented Mar 12, 2018

What if we change the API of this to just export a leveldown? Then if someone wants to use encodings they can wrap it in levelup(encoding(..)) themself. As long as the provided levelup doesn't use encodings, it would be fine, right?

And thinking about: Wouldn't it be generally be simpler to just have a module that takes a leveldown instance and returns a sublevel that also passes abstract-leveldown? Or am I missing something? 🤔

@vweevers
Copy link
Member

What if we change the API of this to just export a leveldown? Then if someone wants to use encodings they can wrap it in levelup(encoding(..)) themself.

It does already export this, you can require('subleveldown/leveldown') if you want. But that may not even be necessary. Since levelup no longer comes with encodings, I guess it makes sense that when such a db is wrapped with subleveldown it also doesn't come with encodings. Just have to document that fact, recommend usage of level, and release a major.

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.

Wouldn't it be generally be simpler to just have a module that takes a leveldown instance and returns a sublevel that also passes abstract-leveldown?

Perhaps, but that's something for a new module, to be discussed elsewhere. It doesn't fit subleveldown, which quite conveniently wraps sublevels with levelup.

@ralphtheninja
Copy link
Member

Just hit this issue today, passing a level@3 to current subleveldown and it tries to double decode json

@emilbayes Good finding. This should be properly documented in e.g. UPGRADING.md etc.

@ralphtheninja
Copy link
Member

@finnp Thanks for your work on this! Will break it apart into smaller changes. Hope you don't mind :)

@ralphtheninja
Copy link
Member

v3.0.0-rc1

@finnp finnp deleted the update-level branch June 3, 2018 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants