nedb-promises-ts
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-4 • Public • Published

Nedb for modern javascript

Nedb with promises and typescript definitions

for plain Nedb typings see ramiroaisen/nedb-types


install

npm i nedb-promises-ts

Usage

import Nedb from "nedb-promises-ts";
 
const collection = new Nedb<MyTypeHere>({autoload: true});
 
// or load after
await collection.loadDatabase();
 
// find
const documents = await collection.find({some: "query"})
                .sort({some: 1})
                .skip(5)
                .limit(10)
                .projection({_id: 0, some: 1}))
 
// OR
const cursor = collection.find(...);
cursor.skip(5);
 
cursor.then(documents =>  ... )
 
// same as 
cursor.exec().then(documents => ... )
 
// findOne
const doc = await collection.findOne(filterFilterQuery<Document<T>>, projectionProjection<Document<T>>);
 
// update
const res = await collection.update(filterFilterQuery<Document<T>>, updateUpdateQuery<Document<T>>, options?: UpdateOptions);
 
// remove
const numAffected = await collection.remove(filterFilterQuery<Document<T>>) 
 
// index
await collection.ensureIndex(fieldNamekeyof Document<T>, optionsIndexOptions);
 
// and so on...
 

Everything is this repo works as expected and has a typescript definition

The functions have the same name as in the original nedb

Note: update queries resolves to an object with this props

numAffectednumber
upsertboolean
documentDocument<T> // if options.returnUpdatedDocs set to true and options.multi set to falsy value
documentsDocument<T>[] // if options.returnUpdatedDocs set to true and options.multi set to truthly value

More Notes

Cursor objects has a .cursor prop that points to the original nedb cursor

Datastore objects has a .nedb prop that points to the original nedb datastore

So if you must you can do collection.nedb.someOp((err, result) => ()}

If you have a comment open an issue in this repo :)

Package Sidebar

Install

npm i nedb-promises-ts

Weekly Downloads

15

Version

0.0.1-4

License

ISC

Unpacked Size

28.6 kB

Total Files

12

Last publish

Collaborators

  • ramiroaisen