Skip to content

dreyacosta/somewhere.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

somewhere.js Build Status

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);

/** Result: Saved Object (autogenerated id)
  {
    id: "0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1",
    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."
  }
*/

Find one

db.findOne('collection', query);
db.findOne('movies', { title: 'Die Hard' });

/** Result: Object
  {
    id: "0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1",
    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."
  }
*/

Find all

db.find('movies', query);
db.find('movies', { genre: 'Action' });

/** Result: Objects array
  [{
    id: "0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1",
    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."
  }]
*/

Update

db.update('movies', id, data);
db.update('movies', '0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1', { genre: "Action/Thriller" });

/** Result: Updated Object
  {
    id: "0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1",
    title: "Die Hard",
    genre: "Action/Thriller",
    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."
  }
*/

Remove

db.remove('movies', id);
db.remove('movies', '0ab7d8a8-ab46-35cd-ccd4-81ccfe81c3f1');
/** Result: Boolean
  true
*/

Clear database

db.clear()

License

This software is free to use under the MIT license.

About

Small in-memory database for Node.js that persists on disk

Resources

License

Stars

Watchers

Forks

Packages

No packages published