Socket
Socket
Sign inDemoInstall

somewhere

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    somewhere

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


Version published
Weekly downloads
318
increased by75.69%
Maintainers
1
Install size
403 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 03 Oct 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc