Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

somewhere

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

somewhere

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

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
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

Package last updated on 03 Oct 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc