0.0.0 • Published 9 months ago

nedb-odm v0.0.0

Weekly downloads
-
License
GPLv3
Repository
github
Last release
9 months ago

nedb-odm

Object Document Model for @seald-io/nedb written in TypeScript/JavaScript

This project is a fork of typescript-nedb-orm

How to install

npm install nedb-odm

or

yarn add nedb-odm

or

pnpm add nedb-odm

How to use

Create an objet extending ORM, parametrised with your class fields interface

Example:

const { ODM } = require('nedb-odm');
class User extends ODM {
    constructor(user){
        super(user)
        this.username = user.username
        this.password = user.password
    }
}

Then, you can use it.

Create an instance of the class to get an object:

const rednexie = new User({
    username: "rednexie",
    password: "******" 
});

Save the object to the database to make it persistent:

await rednexie.save()

Fetch objects from database:

await User.find({ username: "rednexie" })

Delete the object:

await rednexie.delete()

Update your objects in database:

await User.update({ username: "Rednexie" }, { username: "Luc" });

Remove objects from database:

await User.remove({ name: "Rednexie" })

Find one object in database:

await User.find({ username: "rednexie" })
// returns: { username: "rednexie", password: "******" })

Find an object by id in database:

await User.findById("kpOBxczJlr2R5S68")
// returns: { username: "rednexie", password: "******" })

Count the number of objects in database:

await User.count()
// returns: 1

Configuration

User.setModelName('UserCustom') // makes the data be saved in UserCustom.json
User.setClassPath('data') // makes the data be saved in the folder 'data'

License

This project is a fork of typescript-nedb-orm which is licensed under the GNU General Public License v3.0 (GPLv3) - see the LICENSE file for details.

0.0.0

9 months ago