question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bytewise key-encoding on sub-level causes not found on other level

See original GitHub issue

I’m getting odd behavior when using bytewise encoding on a sublevel. The intention is have bytewise encode a number to lex-sortable key, and then have that key appended on the end of the sub-level. It works if I write one value, but the moment I write a second, I can’t read keys from other nested subs. Any idea where I’m going wrong? Docs says a sub-level must encode to a buffer and bytewise should be doing just that.

var sub = require('subleveldown')
var memdown = require('memdown')
var levelup = require('levelup');
var encoding = require('encoding-down');
var bytewise = require('bytewise');
var msgpack = require('msgpack-lite');
var {streamToRx} = require('rxjs-stream');

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

var test1= sub(db, "logs", {valueEncoding: "json" });
var test2 = sub(db, "data");
var nested1 = sub(test2, '1234', { keyEncoding: bytewise, valueEncoding: msgpack })

async function main(){
  await test1.put("1234", "FOO");

  console.log("Got: " + await test1.get("1234"));
  console.log("put one..")
  await nested1.put(10,  10);

  console.log("Got: " + await test1.get("1234"));

  await dumpKeys(db);

  await nested1.put(20,  20);
  console.log("put another..")

  await dumpKeys(db);

  console.log(await test1.get("1234"));

  await dumpKeys(db);
}

async function dumpKeys(db){
  console.log("DUMP:")
  await streamToRx(db.createKeyStream()).forEach(x=>console.log(" " + x.toString()));
}

main().catch(console.log);

Console output:

Got: FOO
put one..
Got: FOO
DUMP:
 !logs!1234
 !data!!1234!B@$
put another..
DUMP:
 !logs!1234
 !data!!1234!B@$
 !data!!1234!B@4
NotFoundError: Key not found in database [1234]
    at D:\Code\geo\node_modules\levelup\lib\levelup.js:160:15
    at D:\Code\geo\node_modules\encoding-down\index.js:50:21
    at Immediate.callNext (D:\Code\geo\node_modules\memdown\memdown.js:162:7)
    at runCallback (timers.js:694:18)
    at tryOnImmediate (timers.js:665:5)
    at processImmediate (timers.js:647:5)

deps:

    "bytewise": "^1.1.0",
    "encoding-down": "^6.0.2",
    "leveldown": "^5.1.0",
    "levelup": "^4.0.2",
    "msgpack-lite": "^0.1.26",
    "rxjs": "^6.5.1",
    "rxjs-stream": "^3.0.2",
    "subleveldown": "^4.0.0",

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
MeirionHughescommented, Jun 16, 2019

fixed - still failing. I’ve also made sure that my local version of level-codec with your suggested change (https://github.com/Level/codec/compare/master...MeirionHughes:master) is defiantly being loaded.

… anyway I can use charwise and keep all my keys as strings for now.

1reaction
MeirionHughescommented, Jun 16, 2019

okaydoky I’ll test if that fixes my unit-test locally then do the pr.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bytewise-uri - npm Package Health Analysis - Snyk
bytewise -uri. This library implements an URI encoding scheme for concisely encoding bytewise-serializable data structures as URI paths.
Read more >
level-orm - npm
There are 2 other projects in the npm registry using level-orm. ... this.db = sublevel(level(dbPath, { keyEncoding: bytewise, valueEncoding: ...
Read more >
Level-q: Priority Queuing for Leveldb/levelup - Morioh
This module is installed via npm: $ npm install level-q. var queue = require( ... q = queue(level('/db/path', { keyEncoding: bytewise, valueEncoding: 'json'...
Read more >
Coding Standard | Unreal Engine 4.27 Documentation
At Epic, we have a few simple coding standards and conventions. ... If this line is missing or not formatted properly, CIS will...
Read more >
Advances in quantum cryptography - Optica Publishing Group
On the other hand, more practical QKD protocols assume some level of trust ... the information encoded by Alice, and (ii) Eve's action...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found