zaaack / keyv-file

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

How to iterate the data #18

Open kennylbj opened 2 years ago

kennylbj commented 2 years ago

I tried by following code but return error:

 for (const value of (this.keyvStore as any).iterator()) {
      console.log(value);
  }

ERROR : this.keyvStore.iterator is not a function or its return value is not iterable

Is that because the iterator function needs to be defined in keyv-file?

SuiKaSan commented 1 year ago

Hello, did you solve the problem? I'm having the same situation.

kennylbj commented 1 year ago

@SuiKaSan According to this document , the iterator function is needed to be defined in order to iterate over the dataset. It seems that the keyv-file did miss this part.

TyrionFront commented 2 months ago

+1

broekema41 commented 2 months ago

Created a pull request for this feature. Hoping for support to get iterators for keyv-file released. :smiley: It's just so nice for devs to develop locally against some files in stead of having to start a docker-ized memory eating db.

broekema41 commented 2 months ago

Tested the iterator here in a actual project and had to do a bugfix. #22 When merged we can close this ticket as solved.

for await (const [key, value] of this.store.iterator()) {
  console.log(key, value);
};
const myIterator = this.store.iterator();
console.log(await myIterator.next());
console.log(await myIterator.next());