somewhere.js
Small in-memory database for Node.js that persists on disk
Installation
$ npm install somewhere
Usage
Load
var Database = require('somewhere');
Create database
var onlyMemoryDb = new Database();
var memoryDiskDb = new Database('./database.json');
Database connection
var db = new Database('./database.json');
Save
db.save('collection', data);
var movie = {
title: "Die Hard",
genre: "Action",
director: "John McTiernan",
description: "John McClane, officer of the NYPD, tries to save wife Holly
Gennaro and several others, taken hostage by German terrorist Hans Gruber
during a Christmas party at the Nakatomi Plaza in Los Angeles."
};
db.save('movies', movie);
Find one
db.findOne('collection', query);
db.findOne('movies', { title: 'Die Hard' });
Find all
db.find('movies', query);
db.find('movies', { genre: 'Action' });
Update
db.update('movies', id, data);
db.update('movies', '0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1', { genre: "Action/Thriller" });
Remove
db.remove('movies', id);
db.remove('movies', '0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1');
Clear database
db.clear()
License
This software is free to use under the MIT license.