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

nedb-promises

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nedb-promises

A dead-simple promise wrapper for nedb.

  • 1.1.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.3K
increased by118.52%
Maintainers
1
Weekly downloads
 
Created
Source

nedb-promises

A dead-simple promise wrapper for nedb.

const Datastore = require('nedb-promises');
let db = Datastore.create('/path/to/db.db');

// #1
db.find({ field: true })
  .then(...)
  .catch(...);
  
// #2
db.find({ field: true })
  .exec(...)
  .then(...)
  .catch(...);

// #1 and #2 are equivalent

db.findOne({ field: true })
  .then(...)
  .catch(...);
  
db.insert({ doc: 'yourdoc', createdAt: Date.now() })
  .then(...)
  .catch(...);

Usage

Everything works as the original module, with three major exceptions.

  • There are no callbacks.
  • loadDatabase has been renamed to load.
  • You should call Datastore.create(...) instead of new Datastore(...). This way you can access the original nedb properties, such as datastore.persistence.

Check out the original documentation!

load( )

You don't need to call this as the module will automatically detect if the datastore has been loaded or not upon calling any other method.

const Datastore = require('nedb-promises');
let db = Datastore.create('/path/to/db.db');
db.load(...)
  .then(...)
  .catch(...)
find( query [, projection ] )

This will return a Cursor object that works the same way it did before except when you call "exec" it takes no arguments and returns a Promise.

update on Cursor objects

With the 1.1.0 update now you can simply call .then(...) on a Cursor to request the documents in a Promise.

Note that .exec() is still necessary when .find() is in the .then() of a Promise chain (otherwise the promise would be resolved with the Cursor object).

const Datastore = require('nedb-promises');
let db = Datastore.create('/path/to/db.db');

//outside Promise chain
db.find(...)
  .then(...)
  .catch(...)
  
//insinde Promise chain
db.insert(...)
  .then(() => {
    return db.find(...).exec();
  })
  .then(
    // use the retrieved documents
  );
findOne( query [, projection ])

Unlike "find" this will not return a Cursor since it makes no sense to sort or limit a single document. This will simply return a Promise.

other( ... )

All the other methods will take the same arguments as they did before (except the callback) and will return a Promise.

update on the update( ... ) method

This method now (1.1.1) accepts upsert and returnUpdatedDocs as it would with the original module.

Special thanks to npeterkamps for the useful pull requests!

Check out the original documentation!

Keywords

FAQs

Package last updated on 27 Mar 2018

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