snore
v0.0.5
Published
Simple in memory key / value store
Downloads
7
Readme
snore
Simple event based in memory key / value store
Install
npm install snore
Usage
Add
const store = require("snore");
const newEntree = { message: "Hello World!" };
let entree = store.add("messages", newEntree); // {id: 1, message: "Hello World!" }
entree = store.add("messages", newEntree); // {id: 2, message: "Hello World!" }
Listen for events
let entree = store.on("update"); // {id: 2, message: "Hello World!" }
Fetch
let entree = store.fetch("messages", entree.id); // {id: 2, message: "Hello World!" }
Remove
// Set up listener on the remove event
store.on("remove", function() {
// Do something...
});
store.remove("messages", entree.id); // the "remove" event will be called now.
Update
// Set up listener for the update event
store.on("update", function(data) {
if(data.id === entree.id) {
console.log(data); // {id: 2, message: "Goodbye World! }
}
})
let entree = store.update("messages", entree.id, { message: "Goodbye World!" });