hypertrie icon indicating copy to clipboard operation
hypertrie copied to clipboard

I can't filter by list function with prefix

Open hyhkjiy opened this issue 3 years ago • 0 comments

Description

When I use the list method and only pass the callback function, I can get all the key-value pairs in the database. But when I use the prefix, I only get an empty array. I'm sure there are keys with prefixes in the database. In order to facilitate the demonstration of the problem, I wrote a simple demo:

import hypertrie from 'hypertrie'
import dotenv from 'dotenv'
import path from 'path'


dotenv.config()

let dbPath = path.join(process.env.EXPORT_FOLDER, process.env.STORE_FILE)

let db = hypertrie(dbPath, { valueEncoding: 'json' })

let key = 'p:4f7bbe1d-fe4a-45cb-bdf4-f2e67fefdb84'

db.put(key, { 'test': 'aaa' }, err => {
    if (err) {
        console.error(err)
    } else {
        db.get(key, (err, value) => {
            if (err) {
                console.error(err)
            } else {
                console.info('get success', value)
            }
        })

        db.list('p', {}, (err, value) => {
            if (err) {
                console.error(err)
            } else {
                console.info('list p success', value)
            }
        })

        db.list((err, value) => {
            if (err) {
                console.error(err)
            } else {
                console.info('list success', value)
            }
        })
    }
})

terminal print: image

Software info:

image image

hyhkjiy avatar Mar 30 '22 11:03 hyhkjiy