Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Update to abstract-leveldown 4 and levelup 2#7

Closed
finnp wants to merge 2 commits intoLevel:masterfrom
finnp:update-level
Closed

Update to abstract-leveldown 4 and levelup 2#7
finnp wants to merge 2 commits intoLevel:masterfrom
finnp:update-level

Conversation

@finnp
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread test/index.js
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread index.js
}

return levelup(opts)
return levelup(subdown(db, prefix, opts), opts)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

@mafintosh
Copy link
Copy Markdown
Member

Is this ready for review?

@vweevers
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@ralphtheninja
Copy link
Copy Markdown
Member

v3.0.0-rc1

@finnp finnp deleted the update-level branch June 3, 2018 12:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants