Skip to content

Commit

Permalink
Default queries to skipping metadata and symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Feb 22, 2024
1 parent d947381 commit 3e40964
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lmdb",
"author": "Kris Zyp",
"version": "2.10.0-beta.5",
"version": "3.0.0-beta.6",
"description": "Simple, efficient, scalable, high-performance LMDB interface",
"license": "MIT",
"repository": {
Expand Down
5 changes: 3 additions & 2 deletions read.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from './native.js';
import { saveKey } from './keys.js';
const IF_EXISTS = 3.542694326329068e-103;
const DEFAULT_BEGINNING_KEY = Buffer.from([5]); // the default starting key for iteration, which excludes symbols/metadata
const ITERATOR_DONE = { done: true, value: undefined };
const Uint8ArraySlice = Uint8Array.prototype.slice;
let getValueBytes = globalBuffer;
Expand Down Expand Up @@ -396,8 +397,8 @@ export function addReadMethods(LMDBStore, {
let snapshot = options.snapshot;
let compression = this.compression;
iterable.iterate = () => {
let currentKey = valuesForKey ? options.key : options.start;
const reverse = options.reverse;
let currentKey = valuesForKey ? options.key : (reverse || 'start' in options) ? options.start : DEFAULT_BEGINNING_KEY;
let count = 0;
let cursor, cursorRenewId, cursorAddress;
let txn;
Expand Down Expand Up @@ -485,7 +486,7 @@ export function addReadMethods(LMDBStore, {
}
}
} else
endAddress = saveKey(options.end, store.writeKey, iterable, maxKeySize);
endAddress = saveKey((reverse && !('end' in options)) ? DEFAULT_BEGINNING_KEY : options.end, store.writeKey, iterable, maxKeySize);
return doPosition(cursorAddress, flags, offset || 0, keySize, endAddress);
}

Expand Down
1 change: 1 addition & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ describe('lmdb-js', function () {
returnedKeys.unshift(key);
value.should.equal(db.get(key));
}
keys.shift(); // remove the symbol test, it should be omitted
keys.should.deep.equal(returnedKeys);
});
it('reverse query range', async function () {
Expand Down

0 comments on commit 3e40964

Please sign in to comment.