Simple-JSONdb icon indicating copy to clipboard operation
Simple-JSONdb copied to clipboard

asyncOnWrite operations should return a Promise

Open mnbroatch opened this issue 4 years ago • 5 comments

As it is, there doesn't seem to be a hook that lets the program know that writing is done, and as a result my database is randomly corrupted on program exit (in the middle of a write operation). Promise wrapper seems the most obvious way to handle this, but we need SOMETHING.

mnbroatch avatar May 25 '21 01:05 mnbroatch

If your concurrency model requires stronger guarantees I'd suggest you to move to a proper storage method instead of hardening this old toy JSON wrapper. Anyway, PRs are always welcome.

nmaggioni avatar May 25 '21 08:05 nmaggioni

It's not hard to roll your own json file disk storage honestly. For starters, if you want to keep your data safe, all saving should happen to a different temp file and then, after success, replace main json file with temp file.

This is how apps with file-based DBs like MSWord, etc do it to prevent corruption. I do not know if this lib works that way.

My point is, don't depend so much on toy libraries like these with limited safeties and overly simplistic implementations. These things are easy to implement by yourself using core node.

iyobo avatar Nov 27 '21 16:11 iyobo

No, it doesn't...but honestly, I think adding Promises would be nice.

a-a-GiTHuB-a-a avatar Mar 03 '22 17:03 a-a-GiTHuB-a-a

Maybe you could submit a PR.

a-a-GiTHuB-a-a avatar Mar 04 '22 18:03 a-a-GiTHuB-a-a

I added a PR including this enhancement: https://github.com/nmaggioni/Simple-JSONdb/pull/18.

a-a-GiTHuB-a-a avatar Mar 10 '22 01:03 a-a-GiTHuB-a-a