promiseifynedb

1.0.2 • Public • Published

promiseifyNedb

A promise wrapper for NeDB.

Installation

Install with NPM:

$ npm i --save promiseifyNedb

Usage

Example using ES7 async/await:

import datastore from 'promiseifyNedb'

async function doDatabaseStuff() {
  let DB = datastore({
     // these options are passed through to nedb.Datastore

     filename: 'my-db.json',

     autoload: true // so that we don't have to call loadDatabase()
  })

  await DB.insert([{
    num: 1, alpha: 'a'
  }, {
    num: 2, alpha: 'b'
  }])

  let document = await DB.findOne({ num: 1 })

  // use NeDB cursors:
  let documents = await DB.cfind({})
    .projection({ num: 1, _id: 0 })
    .exec()
}

doDatabaseStuff()

API

datastore(options)

Returns an object that proxies to an internal nedb.Datastore instance (options are passed through to the NeDB constructor), with promisified methods.

datastore.fromInstance(nedbInstance)

Use this method if you already have a NeDB instance that you want to wrap with the promisified methods.

Readme

Keywords

none

Package Sidebar

Install

npm i promiseifynedb

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

3.19 kB

Total Files

6

Last publish

Collaborators

  • tianwailairenxiaoshuai