zaaack / keyv-file

File storage adapter for Keyv, using json to serialize data.
MIT License
69 stars 10 forks source link

How to iterate over all elements #2

Closed Kikobeats closed 7 years ago

Kikobeats commented 7 years ago

Hello,

Reading Keyv, I see all storages follow Map API.

In my user case, I'm using keyv-file and I need to iterate over all values. Ideally, using Map.prototype.forEach().

After review the code I see method is not implemented. I can do it, but any tip for do that?

Load all the file in memory could be bloat. A good solution could create a readable msgpack5 stream and consume the data.

What do you think?

zaaack commented 7 years ago

Just published a new version v0.1.7, add a .keys() method to get all keys.

keyv-file is a simple adapter of keyv, which means not all APIs of Map need to be implemented, only those keyv required.

If we implement all methods in msgpack5 stream, this would slow the get method, and I don't have any experiences of implementing an index system. Fortunately it is just a simple in-memory cache library with lightweight fs backup support, and is very easy to switch to other adapters like keyv-redis, keyv-postgres, etc.

But I think is ok to have a stream-based API if we provide it as a option, PR's are welcome!

Kikobeats commented 7 years ago

oh thanks! I think that for now is ok 😄