[Node] Json Database for Node-RED

820 views
Skip to first unread message

Antoine Aflalo

unread,
Jul 12, 2014, 1:07:46 PM7/12/14
to node...@googlegroups.com
Hi Node-RED,

I created a database that use JSON file to store the data.

The major advantage of my node compared to other real database is its weight. If you don't need to work with simultaneous access and you are already using the JSON node and file node to store data, this Database Node is for you.

The database load the JSON file into the memory, when needed, and at every change save the data into the file. (This behaviour can be configured to only save when the node is stopped). In other word, it's a light-weight memory database using JavaScript object with persistence.

to Install the node : 
npm install json-db-node-red
It contains 2 Nodes that are put into Storage. One to store the Data and the other to retrieve it.

The major concept I implemented is DataPath. It share it's idea from XMLPath that you use to browse an XML file. 

Example:
This is the data stored at the root of the database. 
{
   "test":"test",
   "json":{
      "test":[
         "test"
      ],
      "important":5
   },
   "new":"cool"
}
To access the array ['test'] the DataPath is : /test/json/test
This path can be used to retrieve or to change the data. And by changing I mean either overriding it or merging with new data.

More information on the Github of the library : https://github.com/Belphemur/node-json-db

Hoping it will be useful to anybody else than me. Btw, the library is highly tested with a coverage of 94% and completely synchronized.
--
Antoine Aflalo

Antoine Aflalo

unread,
Apr 5, 2015, 5:45:30 AM4/5/15
to node...@googlegroups.com
Hello,

I've updated this library to manage arrays.


You can now access directly the underlying array in your datapath.
Example : 
{
   "test":"test",
   "json":{
      "test":[
         "test"
      ],
      "important":5
   },
   "new":"cool"
}

/json/test[0] will return "test"
It mean also you add new entry to the array with changing the index.

If you want this feature, you need to to an
npm update json-db-node-red
to update the node in Node-RED.
Reply all
Reply to author
Forward
0 new messages