We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
with a custom encoder:
let fooEncoding = { encode: (x) => x.message, decode: (x) => { return { message: String(x) }; }, type: "foo", buffer: false }
when you batch with the option to use the encoder:
await new Promise(done => db.batch() .put({ message: "john" }, "adams") .put({ message: "james" }, "kirk") .write({ keyEncoding: fooEncoding }, done));
then iterate:
let it = db.iterator({ keyEncoding: fooEncoding }); while (true) { let item = await new Promise((r, x) => { it.next((err, key, value) => { if (err == null && key === undefined && value === undefined) r(); if (err != null) x(err); r({ key: key, value: value }); }); }); if (item == undefined) break; console.log(item); }
keys is stored as "[object Object]" for both.
If you go through put directly:
put
await new Promise((r, x) => db.put( { message: "john" }, "adams", { keyEncoding: fooEncoding }, (err) => { if (err) x(err); r() } )); await new Promise((r, x) => db.put( { message: "james" }, "kirk", { keyEncoding: fooEncoding }, (err) => { if (err) x(err); r() } ));
OR, use the array batch version:
await new Promise((r, x) => db.batch([ { type: "put", key: { message: "john" }, value: "adams" }, { type: "put", key: { message: "james" }, value: "kirk" }], { keyEncoding: fooEncoding }, (e) => ((e) ? x(e) : r())));
You get the expected result:
{ key: { message: 'james' }, value: 'kirk' } { key: { message: 'john' }, value: 'adams' }
The text was updated successfully, but these errors were encountered:
Discussing a general solution in Level/levelup#633.
Sorry, something went wrong.
No branches or pull requests
with a custom encoder:
when you batch with the option to use the encoder:
then iterate:
keys is stored as "[object Object]" for both.
If you go through
put
directly:OR, use the array batch version:
You get the expected result:
The text was updated successfully, but these errors were encountered: