Giter Club home page Giter Club logo

nedb-promises-ts's Introduction

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(filter: FilterQuery<Document<T>>, projection: Projection<Document<T>>);

// update
const res = await collection.update(filter: FilterQuery<Document<T>>, update: UpdateQuery<Document<T>>, options?: UpdateOptions);

// remove
const numAffected = await collection.remove(filter: FilterQuery<Document<T>>) 

// index
await collection.ensureIndex(fieldName: keyof Document<T>, options: IndexOptions);

// 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

numAffected: number
upsert: boolean
document: Document<T> // if options.returnUpdatedDocs set to true and options.multi set to falsy value
documents: Document<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 :)

nedb-promises-ts's People

Contributors

ramiroaisen avatar sguesdon avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.