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

Inserts fail after 16 items in attached code sample #46

Closed
aral opened this issue May 21, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@aral
Copy link

commented May 21, 2018

To reproduce

Run the following code more than 16 times – e.g., if called index.js: (node index.js):

const { nSQL } = require('nano-sql')

async function start () {
  const connectionResult = await nSQL('hellodb')
    .model([
      {key: 'id', type: 'int', props: ['pk', 'ai']},
      {key: 'date', type: 'string'},
      {key: 'description', type: 'string'},
      {key: 'done', type: 'int'}
    ])
    .config({
      mode: 'PERM'
    })
    .connect()

  const addResult = await Promise.all([
    nSQL('hellodb').query('upsert', { date: new Date(), description: 'First item', done: 0 }).exec(),
    nSQL('hellodb').query('upsert', { date: new Date(), description: 'Second item', done: 1 }).exec(),
    nSQL('hellodb').query('upsert', { date: new Date(), description: 'Third item', done: 0 }).exec()
  ])

  console.log(addResult)

  const selectResult = await nSQL('hellodb').query('select').where(['done', '>', 0]).exec()

  console.log(selectResult)
  console.log(selectResult.length)
}

start()

What should happen

The length of the results from the select query should increase steadily.

What actually happens

New inserts begin to fail after 16 copies of the second item have been inserted. (Inserts continue to work for the first and third items.)

Also, the generated IDs are rather odd. I’m not sure if this is for the lexicographical sorting that LevelDB uses:

[{ date: 'Mon May 21 2018 15:42:06 GMT+0100 (IST)',
    description: 'Second item',
    done: 1,
    id: 2 },
{ date: 'Mon May 21 2018 15:42:25 GMT+0100 (IST)',
    description: 'Second item',
    done: 1,
    id: 32 },
{ date: 'Mon May 21 2018 15:42:30 GMT+0100 (IST)',
    description: 'Second item',
    done: 1,
    id: 332 },
… 
{ date: 'Mon May 21 2018 15:42:44 GMT+0100 (IST)',
    description: 'Second item',
    done: 1,
    id: 3333333333333332 }]

Note: I was initially doing this in a “transaction” block and seeing the same results but refactored to remove the “transaction” based on #35 (comment) to rule that out as a factor.

@ClickSimply

This comment has been minimized.

Copy link
Owner

commented May 21, 2018

Hey thanks for the bug report, this was related to how LevelDB was handling the numerical primary keys.

I've patched the issue, if you npm install from github you'll get v1.6.2 with the fix. I'll likely push 1.6.2 to NPM later today.

Best,
Scott

@aral

This comment has been minimized.

Copy link
Author

commented May 22, 2018

@ClickSimply Thanks, Scott :) Just did a quick review of the commit and verified on my end. Fixed in c8a9814. Closing.

@aral aral closed this May 22, 2018

@ClickSimply ClickSimply added the bug label Jun 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.