Object Document Model for @seald-io/nedb written in TypeScript/JavaScript
This project is a fork of typescript-nedb-orm
npm install nedb-odm
or
yarn add nedb-odm
or
pnpm add nedb-odm
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 ODM({
name: "Luc",
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({ name: "Luc" }, { name: "Rednexie" });
Remove objects from database:
await User.remove({ name: "Rednexie" })
Find one object in database:
await User.find({ username: "rednexie" })
// returns: { name: "Rednexie", username: "rednexie", password: "******" })
Find an object by id in database:
await User.findById("kpOBxczJlr2R5S68")
// returns: { name: "Rednexie", username: "rednexie", password: "******" })
Count the number of objects in database:
await User.count()
// returns: 1
Store databases in another directory:
ODM.path = "./ODM";
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.