ahmetbcakici/js-json-db

Does this need to be wrapped in a class?

Opened this issue · 3 comments

I feel like the package should be usable just by grabbing functions from the module, without any class constructor call after the require/import. I've seen that probably the only thing you do in this constructor is make the folder.

However, you might not need to do that because there's this package called fs-extra. You just npm install it and just change the require('fs') to require('fs-extra') and all the regular fs functions will still be there. Then change all your fs.writeFile functions to fs.outputFile and that will make sure that if the folder the file is in doesn't exist, it will make it. Then I believe all your code can be transformed into regular exported functions.

I made an issue because I don't have time for a pull request, I hope it's fine

No problem , thanks :)

Or actually, before you delete the class, I thought it would be better to just make the generate jDB function the constructor, then whenever you need a new database, you literally call new jDB() and it makes one for you, and then instead of calling usejDB() you call functions on that database.

Basically what I mean is instead of making a single class for the entire thing, make one for each database

Yes good idea. Actually if i remember correctly i tried something like this but i got some errors. But i'll work on it again.