MemoryStore.js
Simple way to store your data inside a raw .json file . Built on top of the node.js , the filesystem and lodash library . You can use different json files as models . Again this needs more work and has some experimental methods available such as realtime methods and events ...
it only works on backend / pure node apps such as express / electron / API apps etc etc ...
Table of contents
Installation
npm i memorystore.js --saveyarn add memorystore.js
Usage
First init the main constructor
const MemoryStore = ;const memory = './data.json' // Options is not required truncate: false // The truncate option is by default false
Add
Callback returns two parameters . First one is error and the second one is data itself . The data is schemaless and have an ID field .
const MemoryStore = ;const memory = './data.json' // PATH TO JSON FILEmemory
List
You can list all data or find a specific data . Here is a list of som useful methods .
List all
The listAll() function takes only a function as it's parameter and returns all the data as an array . Here is an example below .
const MemoryStore = ;const memory = './data.json' // PATH TO JSON FILEmemory
Find
EXPERIMENTAL
The find() function takes two parameters and then returns that object / multiple objects in an array responding / matching that specific object . An example is shown below . Here I searched for a data which has Some demo title
as the content for field title . I got that data back with it's ID .
const MemoryStore = ;const memory = './data.json' // PATH TO JSON FILEmemory
Find by ID
This function returns only one object responding to the matching ID
const MemoryStore = ;const memory = './data.json' // PATH TO JSON FILEmemory
Delete
You can delete some specific data using some useful methods exposed by this package
Delete by finding
EXPERIMENTAL This function deletes an object / an array of objects responding the where object please try to use the deleteById method as it's not fully functional yet / can be buggy
const MemoryStore = ;const memory = './data.json' // PATH TO JSON FILEmemory;
Delete by ID
This function deletes an object responding the ID
const MemoryStore = ;const memory = './data.json' // PATH TO JSON FILEmemory
Update
You can update some specific data using some useful methods exposed by this package
Update by finding
EXPERIMENTAL This method updates the object in the main array responding the where object
const MemoryStore = ;const memory = './data.json' // PATH TO JSON FILEmemory;
Update by ID
This function updates an object responding the ID
const MemoryStore = ;const memory = './data.json' // PATH TO JSON FILEmemory
MIT License . Created by Adib Mohsin