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

Support "deep" option in clear() & iterator() #85

Closed
MeirionHughes opened this issue Dec 17, 2019 · 10 comments
Closed

Support "deep" option in clear() & iterator() #85

MeirionHughes opened this issue Dec 17, 2019 · 10 comments
Labels
invalid This doesn't seem right

Comments

@MeirionHughes
Copy link
Member

I've not tested yet, but I'm suspecting that clear on a parent sub doesn't empty any nested subs?

@MeirionHughes MeirionHughes added the question Support or open question(s) label Dec 17, 2019
@MeirionHughes
Copy link
Member Author

okay, actually tested it; doesn't seem to:

  let db = levelup(encoding(memdown()));

  let dbsub = sub(db, "foo");
  let dbsubsub = sub(dbsub, "bar");

  await dbsub.put("A", "a");
  await dbsubsub.put("B", "b");

  await dumpKeys(db);

  await dbsub.clear();

  await dumpKeys(db);
DUMP:
 !foo!!bar!B
 !foo!A
DUMP:
 !foo!!bar!B

I guess I can work around it with something like: await db.clear({gte: "!foo!", lt: "!foo$"})

@vweevers
Copy link
Member

Clearing works the same as iterating (it visits the same keys). Should we forego that symmetry?

@MeirionHughes
Copy link
Member Author

probably not, but perhaps adding an option field? something like "all" to signal you want to clear everything?

@vweevers
Copy link
Member

That might be nice for iterators too.

@vweevers
Copy link
Member

something like "all"

Or "deep". A PR is welcome.

@MeirionHughes
Copy link
Member Author

MeirionHughes commented Dec 17, 2019

but what would be the range?
{gte: prefix, lt: prefix.substring(0, prefix.length - 1) + "$"}?.

I just guessed that lt: ...$ would be the catch all - not sure if that is valid/safe?

@MeirionHughes MeirionHughes added enhancement New feature or request and removed question Support or open question(s) labels Dec 18, 2019
@MeirionHughes MeirionHughes changed the title Does Clear() support removing nested subs? Support "deep" option in clear() & iterator() Dec 18, 2019
@vweevers
Copy link
Member

Looking more closely at this, iterators already include the keys of nested sublevels. Maybe you were hitting a race issue in opening the db?

@vweevers
Copy link
Member

I fail to replicate #85 (comment).

@MeirionHughes
Copy link
Member Author

MeirionHughes commented Dec 21, 2019

you're right; looks like the issue only arises when encoding-down is used - I tried to replicate in existing (subleveldown) test but couldn't, but it is only db = levelup(memdown)

if I remove encoding-down from the code above, it clears properly.

... and I've tried to test that too (var down = encoding(memdown())) in the main test file and can't replicate. no idea what is going on now...

@MeirionHughes MeirionHughes added invalid This doesn't seem right and removed enhancement New feature or request labels Dec 21, 2019
@MeirionHughes
Copy link
Member Author

MeirionHughes commented Dec 21, 2019

dam... I think it might have been a bad version on my monorepo. I forced update to the latest versions and the issue seems to have vanished. Sorry... I thought had updated them all - but I think I had the last memdown major - sorry for wasting your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants