Code Monkey home page Code Monkey logo

lmdb-leveldown's People

Contributors

chrbala avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

brewer-algosec

lmdb-leveldown's Issues

Iterator does not work correctly when provided both upper and lower bound in reverse

The iterator does not go in the correct direction with both an upper and lower bound.

this.curr = reverse ? cursor.goToPrev() : cursor.goToNext();

Example test output:

# test iterator with gte=30 and lte=70 and reverse=true
ok 275 undefined
not ok 276 correct number of entries
  ---
    operator: equal
    expected: 41
    actual:   1
    stack: |-
      Error: correct number of entries
          at Test.assert [as _assert] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:212:54)
          at Test.bound [as _assert] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:64:32)
          at Test.equal.Test.equals.Test.isEqual.Test.is.Test.strictEqual.Test.strictEquals (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:347:10)
          at Test.bound [as is] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:64:32)
          at /Users/chris/lmdb-leveldown/node_modules/abstract-leveldown/abstract/iterator-range-test.js:28:11
          at /Users/chris/lmdb-leveldown/node_modules/abstract-leveldown/testCommon.js:56:11
          at /Users/chris/lmdb-leveldown/src/index.js:281:48
  ...
not ok 277 should be equivalent
  ---
    operator: deepEqual
    expected: |-
      [ { key: '70', value: '0.8025281173721805' }, { key: '69', value: '0.5664507517525017' }, { key: '68', value: '0.10233997012150153' }, { key: '67', value: '0.3480505763258064' }, { key: '66', value: '0.9132791307734551' }, { key: '65', value: '0.030064742250546006' }, { key: '64', value: '0.49373167690324027' }, { key: '63', value: '0.12620420026129908' }, { key: '62', value: '0.11216823705999612' }, { key: '61', value: '0.42510185325347893' }, { key: '60', value: '0.9624005486051628' }, { key: '59', value: '0.5568737819443985' }, { key: '58', value: '0.5319237025637298' }, { key: '57', value: '0.8552353376818715' }, { key: '56', value: '0.6401857734726797' }, { key: '55', value: '0.7778772324231' }, { key: '54', value: '0.6563670401821771' }, { key: '53', value: '0.4460314320292509' }, { key: '52', value: '0.07948485238433345' }, { key: '51', value: '0.36530754007971344' }, { key: '50', value: '0.9926293454942214' }, { key: '49', value: '0.870681776044933' }, { key: '48', value: '0.40817687400102187' }, { key: '47', value: '0.3876517750820454' }, { key: '46', value: '0.0017991566460582309' }, { key: '45', value: '0.8344979460196531' }, { key: '44', value: '0.2520268489645723' }, { key: '43', value: '0.8325248425789715' }, { key: '42', value: '0.001318505225654354' }, { key: '41', value: '0.6002752426781577' }, { key: '40', value: '0.9062894500219179' }, { key: '39', value: '0.5091017741121526' }, { key: '38', value: '0.556665716180794' }, { key: '37', value: '0.6994867761581447' }, { key: '36', value: '0.6354089503475413' }, { key: '35', value: '0.3067917310062098' }, { key: '34', value: '0.9483960001944651' }, { key: '33', value: '0.07456138004585422' }, { key: '32', value: '0.5269703145924365' }, { key: '31', value: '0.11930046918457604' }, { key: '30', value: '0.95193243077822' } ]
    actual: |-
      [ { key: '30', value: '0.95193243077822' } ]
    stack: |-
      Error: should be equivalent
          at Test.assert [as _assert] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:212:54)
          at Test.bound [as _assert] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:64:32)
          at Test.deepEqual.Test.deepEquals.Test.isEquivalent.Test.same (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:380:10)
          at Test.bound [as same] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:64:32)
          at /Users/chris/lmdb-leveldown/node_modules/abstract-leveldown/abstract/iterator-range-test.js:29:11
          at /Users/chris/lmdb-leveldown/node_modules/abstract-leveldown/testCommon.js:56:11
          at /Users/chris/lmdb-leveldown/src/index.js:281:48
  ...

'regeneratorRuntime is not defined' whem requiring

Hello,

This is pretty self explanatory I hope:

> require('lmdb-leveldown')
Thrown:
ReferenceError: regeneratorRuntime is not defined
    at /home/lewis/dbtest/node_modules/lmdb-leveldown/build/index.js:450:47
    at /home/lewis/dbtest/node_modules/lmdb-leveldown/build/index.js:513:4

Node version v10.16.0. Downloads fine, I can require node-lmdb no problem.

Confirm correct sorting of keys in iterator

This may be resolved with #2. It looks like abstract-leveldown is expecting the keys to be sorted alphabetically, and I'm not sure what the underlying node-lmdb is sorting by.

Example test output:

# test iterator with gte=49999 (midway)
ok 206 undefined
not ok 207 correct number of entries
  ---
    operator: equal
    expected: 50
    actual:   0
  ...
not ok 208 should be equivalent
  ---
    operator: deepEqual
    expected: |-
      [ { key: '50', value: '0.9926293454942214' }, { key: '51', value: '0.36530754007971344' }, { key: '52', value: '0.07948485238433345' }, { key: '53', value: '0.4460314320292509' }, { key: '54', value: '0.6563670401821771' }, { key: '55', value: '0.7778772324231' }, { key: '56', value: '0.6401857734726797' }, { key: '57', value: '0.8552353376818715' }, { key: '58', value: '0.5319237025637298' }, { key: '59', value: '0.5568737819443985' }, { key: '60', value: '0.9624005486051628' }, { key: '61', value: '0.42510185325347893' }, { key: '62', value: '0.11216823705999612' }, { key: '63', value: '0.12620420026129908' }, { key: '64', value: '0.49373167690324027' }, { key: '65', value: '0.030064742250546006' }, { key: '66', value: '0.9132791307734551' }, { key: '67', value: '0.3480505763258064' }, { key: '68', value: '0.10233997012150153' }, { key: '69', value: '0.5664507517525017' }, { key: '70', value: '0.8025281173721805' }, { key: '71', value: '0.5920517761246549' }, { key: '72', value: '0.7022464461638869' }, { key: '73', value: '0.10957992173264319' }, { key: '74', value: '0.7761877436457496' }, { key: '75', value: '0.5781361569669583' }, { key: '76', value: '0.3111166336007185' }, { key: '77', value: '0.4878780537177789' }, { key: '78', value: '0.12655914496335186' }, { key: '79', value: '0.38618150055929523' }, { key: '80', value: '0.31609012678322257' }, { key: '81', value: '0.6589613745332377' }, { key: '82', value: '0.6048494277682703' }, { key: '83', value: '0.2066701342922257' }, { key: '84', value: '0.0018538658409072983' }, { key: '85', value: '0.8492683128917726' }, { key: '86', value: '0.0848514102379645' }, { key: '87', value: '0.9711296854693521' }, { key: '88', value: '0.49853902528205385' }, { key: '89', value: '0.9740776483919469' }, { key: '90', value: '0.6530275273713964' }, { key: '91', value: '0.25511761710292546' }, { key: '92', value: '0.28199455595791534' }, { key: '93', value: '0.57805842900936' }, { key: '94', value: '0.20249379034314852' }, { key: '95', value: '0.3205214395313847' }, { key: '96', value: '0.15968226699990007' }, { key: '97', value: '0.6626543905212701' }, { key: '98', value: '0.08386572138126924' }, { key: '99', value: '0.8048711309013743' } ]
    actual: |-
      []
    stack: |-
      Error: should be equivalent
          at Test.assert [as _assert] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:212:54)
          at Test.bound [as _assert] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:64:32)
          at Test.deepEqual.Test.deepEquals.Test.isEquivalent.Test.same (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:380:10)
          at Test.bound [as same] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:64:32)
          at /Users/chris/lmdb-leveldown/node_modules/abstract-leveldown/abstract/iterator-range-test.js:29:11
          at /Users/chris/lmdb-leveldown/node_modules/abstract-leveldown/testCommon.js:56:11
          at /Users/chris/lmdb-leveldown/src/index.js:281:48
  ...

Iterator does not work correctly when the supplied range is not a key

The iterator currently starts with a key when getting the initial value to iterate through. This does not work if the range is defined by values that are not keys.

lmdb-leveldown/src/index.js

Lines 144 to 168 in 5d34800

const getInitialCurrentValue = (
{ gt, gte, lt, lte, reverse }: IteratorOptionsType,
cursor: *
) => {
const invalid = (a: string, b: string) =>
`${a} can not be provided with ${b}`;
if (gt) {
if (gte) throw new Error(invalid('gt', 'gte'));
if (reverse) return cursor.goToLast();
cursor.goToKey(gt);
return cursor.goToNext();
} else if (gte) return cursor.goToKey(gte);
else if (lt) {
if (lte) throw new Error(invalid('lt', 'lte'));
if (reverse) {
cursor.goToKey(lt);
return cursor.goToPrev();
}
return cursor.goToFirst();
} else if (lte) return reverse ? cursor.goToKey(lte) : cursor.goToFirst();
return reverse ? cursor.goToLast() : cursor.goToFirst();
};

Example test output:

# test iterator with gte=49.5 (midway)
ok 200 undefined
not ok 201 correct number of entries
  ---
    operator: equal
    expected: 50
    actual:   0
  ...
not ok 202 should be equivalent
  ---
    operator: deepEqual
    expected: |-
      [ { key: '50', value: '0.9926293454942214' }, { key: '51', value: '0.36530754007971344' }, { key: '52', value: '0.07948485238433345' }, { key: '53', value: '0.4460314320292509' }, { key: '54', value: '0.6563670401821771' }, { key: '55', value: '0.7778772324231' }, { key: '56', value: '0.6401857734726797' }, { key: '57', value: '0.8552353376818715' }, { key: '58', value: '0.5319237025637298' }, { key: '59', value: '0.5568737819443985' }, { key: '60', value: '0.9624005486051628' }, { key: '61', value: '0.42510185325347893' }, { key: '62', value: '0.11216823705999612' }, { key: '63', value: '0.12620420026129908' }, { key: '64', value: '0.49373167690324027' }, { key: '65', value: '0.030064742250546006' }, { key: '66', value: '0.9132791307734551' }, { key: '67', value: '0.3480505763258064' }, { key: '68', value: '0.10233997012150153' }, { key: '69', value: '0.5664507517525017' }, { key: '70', value: '0.8025281173721805' }, { key: '71', value: '0.5920517761246549' }, { key: '72', value: '0.7022464461638869' }, { key: '73', value: '0.10957992173264319' }, { key: '74', value: '0.7761877436457496' }, { key: '75', value: '0.5781361569669583' }, { key: '76', value: '0.3111166336007185' }, { key: '77', value: '0.4878780537177789' }, { key: '78', value: '0.12655914496335186' }, { key: '79', value: '0.38618150055929523' }, { key: '80', value: '0.31609012678322257' }, { key: '81', value: '0.6589613745332377' }, { key: '82', value: '0.6048494277682703' }, { key: '83', value: '0.2066701342922257' }, { key: '84', value: '0.0018538658409072983' }, { key: '85', value: '0.8492683128917726' }, { key: '86', value: '0.0848514102379645' }, { key: '87', value: '0.9711296854693521' }, { key: '88', value: '0.49853902528205385' }, { key: '89', value: '0.9740776483919469' }, { key: '90', value: '0.6530275273713964' }, { key: '91', value: '0.25511761710292546' }, { key: '92', value: '0.28199455595791534' }, { key: '93', value: '0.57805842900936' }, { key: '94', value: '0.20249379034314852' }, { key: '95', value: '0.3205214395313847' }, { key: '96', value: '0.15968226699990007' }, { key: '97', value: '0.6626543905212701' }, { key: '98', value: '0.08386572138126924' }, { key: '99', value: '0.8048711309013743' } ]
    actual: |-
      []
    stack: |-
      Error: should be equivalent
          at Test.assert [as _assert] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:212:54)
          at Test.bound [as _assert] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:64:32)
          at Test.deepEqual.Test.deepEquals.Test.isEquivalent.Test.same (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:380:10)
          at Test.bound [as same] (/Users/chris/lmdb-leveldown/node_modules/tape/lib/test.js:64:32)
          at /Users/chris/lmdb-leveldown/node_modules/abstract-leveldown/abstract/iterator-range-test.js:29:11
          at /Users/chris/lmdb-leveldown/node_modules/abstract-leveldown/testCommon.js:56:11
          at /Users/chris/lmdb-leveldown/src/index.js:281:48
  ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.