Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Promisified nedb wrapper

NotificationsYou must be signed in to change notification settings

jrop/nedb-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A promise wrapper forNeDB.

Installation

Install with NPM:

$ npm i --save nedb-promise

Usage

Example using ES7 async/await:

importdatastorefrom'nedb-promise'asyncfunctiondoDatabaseStuff(){letDB=datastore({// these options are passed through to nedb.Datastorefilename:'my-db.json',autoload:true// so that we don't have to call loadDatabase()})awaitDB.insert([{num:1,alpha:'a'},{num:2,alpha:'b'}])letdocument=awaitDB.findOne({num:1})// use NeDB cursors:letdocuments=awaitDB.cfind({}).projection({num:1,_id:0}).exec()}doDatabaseStuff()

API

datastore(options)

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

It also includes extension methodscfind(...),cfindOne(...), andccount(...) that return promisified cursors, so that you may do:

letresults=awaitmyDataStore.cfind({moo:'goo'}).projection({moo:1,_id:0})// see NeDB cursor methods.exec()

datastore.fromInstance(nedbInstance)

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

Testing

Run tests with mocha (after building):

$ mocha test.js

License

Copyright (c) 2015, Jonathan Apodacajrapodaca@gmail.comPermission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


[8]ページ先頭

©2009-2025 Movatter.jp