electron-json-storage icon indicating copy to clipboard operation
electron-json-storage copied to clipboard

added multi-directory support

Open kfardanesh opened this issue 8 years ago • 5 comments

An initial start to add multi-directory support while keeping existing functionality. Looking to get help/advice from community to make code more robust and describe what functionality they would like to see. I understand that this involves a lot more edge cases and effort to maintain than the single directory so also looking to gauge interest since this is one of the more popular repos for json storage on electron.

Added capability to prefix key with directory for get(), set(), has(), remove() (i.e. "testfolder/foo" will get, set, has, or remove foo under the testfolder directory).

  • "foo" will look/create/check/remove key at "{apppath}/storage/foo.json"
  • "testfolder/foo" will look/create/check/remove key at "{apppath}/storage/testfolder/foo.json"
  • "../testfolder/foo" will look/create/check/remove key at "{apppath}/storage/testfolder/foo.json" (i.e. parent directory symbol ".." gets ignored)
  • "testfolder/testfolder/foo" will look/create/check/remove key at "{apppath}/storage/testfolder/testfolder/foo.json"

Also extended functions getAll(), keys(), clear()* to allow optional directory parameter (i.e. "testfolder" will getAll, keys or clear* under the testfolder directory)

  • keys function would return directories, so added check for file extension (if no file extension, assume folder

getMany() is tricky and needs some work to determine functionality with multi-directories.

*Currently clear() removes the directory passed to function. Can be changed. **All current test cases pass with exception of utils test function which I commented out for time being. ***Can work on adding test cases if there is enough interest

kfardanesh avatar Mar 03 '17 02:03 kfardanesh

Hi @kfardanesh ,

Thanks a lot for the PR, and sorry for not having time to look at this during the weekend. I'll try to do so on Monday :)

jviotti avatar Mar 06 '17 04:03 jviotti

Let's add some functions to set and get the default settings location, for example: storage.setUserDataPath() and storage.getUserDataPath().

Having to specify the directory each time looks like unnecessary extra overhead.

jviotti avatar Mar 06 '17 19:03 jviotti

I reverted my changes to your original functions and added the get and set functions for the current working directory. All original test cases still work.

A slight annoyance with most recent commit is that any new directories created under the base 'storage' folder will persist unless deleted manually.

kfardanesh avatar Mar 07 '17 03:03 kfardanesh

Any update on this feature? Either directory support in the keys or changing the user path. I would be interested in this functionality.

Yoann-Pearson avatar Jul 19 '17 18:07 Yoann-Pearson

@stromboul I don't think the author is still working on it. You're free to take over using the suggestions in this PR!

jviotti avatar Jul 27 '17 12:07 jviotti