azu / kvs

Lightweight key-value storage library for Browser, Node.js, and In-Memory.
MIT License
182 stars 6 forks source link

Iterating a specific kvsEnvStorage returns all key-value pairs for all databases #20

Closed berkbuzcu closed 2 years ago

berkbuzcu commented 2 years ago

Let's say I've got two collections:

const A = async () => { return await kvsEnvStorage({ name: "a_col", version: 1, }) }

const B = async () => { return await kvsEnvStorage({ name: "b_col", version: 1, }) }

const storage = await A() for await (const [key, value] of storage) { console.log(key, value) }

Will print items that belong to storage B as well.

Is this an error of my usage, or a bug?

azu commented 2 years ago

Thanks to report!

Which env do you run this code? @kvs/env work on browser and node

browser(IndexedDB sperate table name) https://github.com/azu/kvs/blob/bfa33d7dba44e805ea4ee9e636995aa6ce447c8f/packages/indexeddb/src/index.ts#L197-L235

node https://github.com/azu/kvs/blob/bfa33d7dba44e805ea4ee9e636995aa6ce447c8f/packages/storage/src/storage.ts#L178-L195 It seems that it has a bug that does not separate namespace… (name is not used…)

berkbuzcu commented 2 years ago

Thanks to report!

Which env do you run this code? @kvs/env work on browser and node

browser(IndexedDB sperate table name)

https://github.com/azu/kvs/blob/bfa33d7dba44e805ea4ee9e636995aa6ce447c8f/packages/indexeddb/src/index.ts#L197-L235

node

https://github.com/azu/kvs/blob/bfa33d7dba44e805ea4ee9e636995aa6ce447c8f/packages/storage/src/storage.ts#L178-L195

It seems that it has a bug that does not separate namespace… (name is not used…)

Hello, thanks for the quick reply.

We are using nodejs + discord.js so we used @kvs/env

azu commented 2 years ago

Thanks to confirm. I understant it is bug.

21 will fix it, but it will includes breaking change.

so, I plan to publish it as major update. (probably, weekend)

berkbuzcu commented 2 years ago

We walked around this but it's kind of a problem if it fetches every item at every call.

Thanks for the fix!

azu commented 2 years ago

This issue is fixed in https://github.com/azu/kvs/releases/tag/v2.0.0

Thanks for report!