All Projects → bajankristof → Nedb Promises

bajankristof / Nedb Promises

Licence: other
A dead-simple promise wrapper for nedb.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Nedb Promises

mongoose-aggregate-paginate-v2
A cursor based custom aggregate pagination library for Mongoose with customizable labels.
Stars: ✭ 103 (-45.79%)
Mutual labels:  promise, callback, cursor
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (-89.47%)
Mutual labels:  promise, callback
lightflow
A tiny Promise-inspired control flow library for browser and Node.js.
Stars: ✭ 29 (-84.74%)
Mutual labels:  promise, callback
Replace In File
A simple utility to quickly replace contents in one or more files
Stars: ✭ 369 (+94.21%)
Mutual labels:  promise, callback
Escape From Callback Mountain
Example Project & Guide for mastering Promises in Node/JavaScript. Feat. proposed 'Functional River' pattern
Stars: ✭ 249 (+31.05%)
Mutual labels:  promise, callback
do
Simplest way to manage asynchronicity
Stars: ✭ 33 (-82.63%)
Mutual labels:  promise, callback
Mongoose Paginate V2
A cursor based custom pagination library for Mongoose with customizable labels.
Stars: ✭ 283 (+48.95%)
Mutual labels:  callback, cursor
run exclusive
⚡🔒 Wait queue for function execution 🔒 ⚡
Stars: ✭ 22 (-88.42%)
Mutual labels:  promise, callback
Zcoil
Elegant access to data
Stars: ✭ 20 (-89.47%)
Mutual labels:  promise, callback
Gollback
Go asynchronous simple function utilities, for managing execution of closures and callbacks
Stars: ✭ 55 (-71.05%)
Mutual labels:  promise, callback
Tupl
The Unnamed Persistence Library
Stars: ✭ 83 (-56.32%)
Mutual labels:  database, cursor
Massive Js
A data mapper for Node.js and PostgreSQL.
Stars: ✭ 2,521 (+1226.84%)
Mutual labels:  promise, database
Amazon Mws
Amazon MWS NodeJS Wrapper
Stars: ✭ 196 (+3.16%)
Mutual labels:  promise, callback
Trilogy
TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
Stars: ✭ 195 (+2.63%)
Mutual labels:  promise, database
Poloniex Api Node
Poloniex API client for REST and WebSocket API
Stars: ✭ 138 (-27.37%)
Mutual labels:  promise, callback
Thunks
A small and magical composer for all JavaScript asynchronous.
Stars: ✭ 523 (+175.26%)
Mutual labels:  promise, callback
Bach
Compose your async functions with elegance.
Stars: ✭ 117 (-38.42%)
Mutual labels:  promise, callback
Metasync
Asynchronous Programming Library for JavaScript & Node.js
Stars: ✭ 164 (-13.68%)
Mutual labels:  promise, callback
Pdo
Connecting to MySQL in PHP using PDO.
Stars: ✭ 187 (-1.58%)
Mutual labels:  database
Vkbottle
Homogenic! Customizable asynchronous VK API framework
Stars: ✭ 191 (+0.53%)
Mutual labels:  callback

nedb-promises

A dead-simple promise wrapper for nedb.

Check out the docs.

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

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

// #1 and #2 are equivalent

datastore.findOne({ field: true })
  .then(...)
  .catch(...)
  
datastore.insert({ doc: 'yourdoc' })
  .then(...)
  .catch(...)
  
// or in an async function
async function findSorted(page, perPage = 10) {
  return await datastore.find(...)
      .sort(...)
        .limit(perPage)
        .skip(page * perPage)
}

Installation

npm install --save nedb-promises

Usage

Everything works as the original module, with four 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.
  • As of v2.0.0 the module supports events 😎... Check out the docs about events!

Check out the original docs!

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 datastore = Datastore.create('/path/to/db.db')
datastore.load(...)
  .then(...)
  .catch(...)

find( [query], [projection] ), findOne( [query], [projection] ), count( [query] )

These methods 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. The cool thing about this implementation of the Cursor is that it behaves like a Promise. Meaning that you can await it and you can call .then() on it.

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

//outside Promise chain
datastore.find(...)
  .then(...)
  .catch(...)
  
//insinde Promise chain
datastore.insert(...)
  .then(() => {
    return datastore.find(...)
  })
  .then(
    // use the retrieved documents
  )

;(async () => {
  await datastore.find(...).sort(...).limit()
})()

other( ... )

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

Check out the docs.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].