kriszyp / lmdb-js

Simple, efficient, ultra-fast, scalable data store wrapper for LMDB
Other
522 stars 44 forks source link

why data get replaced and output only one when openDB function set to `nodes` #248

Closed dennis0324 closed 1 year ago

dennis0324 commented 1 year ago

so I try the following codes and it seems to have a little problem when I set openDB name to nodes it only return one value. Am I doing something wrong?

import { open } from 'lmdb'; // or require
import path from 'path';
let myDB = open({
    path: path.join(path.resolve("."),'.nextql','lmdb'),
    // any options go here, we can turn on compression like this:
    compression: true,
});

const nodeDB = myDB.openDB({
    name:'tests',
    dupSort:true,
    encoding:'ordered-binary'
})
const db = myDB.openDB({
    name:'nodes',
    dupSort:true,
    encoding:'ordered-binary'
});

async function asyncRun(){
    await nodeDB.put('test','1')
    await nodeDB.put('test','2')
    await nodeDB.put('test','3')
    await nodeDB.put('test','4')

    for (let value of nodeDB.getValues('test')) {
        console.log(value)
        // iterate values '1', '2', '3', '4'
    }

    await db.put('key1', 'value1');
    await db.put('key1', 'value2');
    await db.put('key1', 'value3');
    await db.put('key1', 'value4');
    for (let value of db.getValues('key1')) {
        console.log(value)
        // iterate values 'value4'
    }
}

;(async () => {
    await asyncRun()
})().catch(err => {
    console.error(err)
    throw err
})

output

1
2
3
4
value4
4
kriszyp commented 1 year ago

This is the output I get:

1
2
3
4
value1
value2
value3
value4

What version of lmdb-js are you using?

dennis0324 commented 1 year ago

I'm using 2.8.2 currently

Here is my dependencies

 "dependencies": {
    "@apollo/server": "^4.7.3",
    "@as-integrations/next": "^2.0.0",
    "@graphql-tools/load-files": "^7.0.0",
    "@graphql-tools/utils": "^10.0.1",
    "@types/node": "20.3.0",
    "@types/react": "18.2.11",
    "@types/react-dom": "18.2.4",
    "@walmartlabs/json-to-simple-graphql-schema": "^3.0.1",
    "axios": "^1.4.0",
    "dotenv": "^16.1.4",
    "eslint": "8.42.0",
    "eslint-config-next": "13.4.5",
    "graphql": "^16.6.0",
    "graphql-tag": "^2.12.6",
    "graphql-tools": "^9.0.0",
    "graphql-yoga": "^4.0.2",
    "i": "^0.3.7",
    "lmdb": "^2.8.2",
    "nanospinner": "^1.1.0",
    "next": "13.4.5",
    "next-themes": "^0.2.1",
    "nextql_schema": "^0.0.10",
    "notion-client": "^6.16.0",
    "notion-types": "^6.16.0",
    "npm": "^9.7.1",
    "quicktype-core": "^23.0.48",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-modal": "^3.16.1",
    "react-notion-x": "^6.16.0",
    "redux": "^4.2.1",
    "ts-node": "^10.9.1",
    "typescript": "5.1.3",
    "webpack": "^5.87.0"
  },
  "devDependencies": {
    "@graphql-codegen/cli": "4.0.1",
    "@graphql-codegen/client-preset": "4.0.1",
    "@graphql-codegen/typescript": "^4.0.1",
    "@graphql-codegen/typescript-resolvers": "^4.0.1",
    "@types/react-modal": "^3.16.0"
  }
dennis0324 commented 1 year ago

Found my problem. I was really dumb. When i delete my existing lmdb store files and it is working totally fine. I'm sorry to bother you