Not a Real DB
A "fake" database for Node.js that stores data in local JSON files, for testing and sample applications.
Usage
Create a DataStore
instance specifying in which folder to store the data, then create a collections for each object type you want to store:
const DataStore = ; const store = './data';const apples = store;const oranges = store;
This will save apples in ./data/apples.json
and oranges in ./data/oranges.json
.
You can then manipulate each collection using the following CRUD operations:
// create a new item; returns a generated idconst id = apples; // => 'BJ4E9mQOG' // list all items in a collectionapples; // => [{id: 'BJ4E9mQOG', variety: 'Gala', weight: 133}] // get a single itemapples; // => {id: 'BJ4E9mQOG', variety: 'Gala', weight: 133} // update an itemapples; // delete an itemapples;
That's it. All operations are synchronous.
Files are read at startup and written after each modification. You can manually edit a JSON file and provide some initial data, as long as you do that before you start the application.
Usage with TypeScript
If you use this module from TypeScript you can specify an interface representing the type of objects stored in each collection. E.g.
; ;; // => apples: Collection<Apple>apples.list; // => Apple[]