0.0.3 • Published 12 months ago
sagitarius v0.0.3
Introduction
Minimal, easy to use, fast Object Document Mapping(ODM) library for NeDB. Supports type-checking and schema validation.
Installation
npm install sagitariusyarn add sagitariuspnpm add sagitariusQuick Start
Create and initialize the model:
import { Model } from "sagitarius";
class User extends BaseModel{
constructor(doc){
super(doc)
Object.assign(this, doc);
}
}Define a schema to be able to perform validation:
User.define("User", {
username: String,
age: Number,
});Create a new user:
const user = new User({ username: "Rednexie", age: 18 });
await user.save()Update user properties:
user.age = 19;
await user.save();API Reference
Instance Methods
async interface.save() Creates a new instance of the model with the provided document.
async interface.delete() Deletes the document from the database.
async interface.toJSON() Converts the document from the database to a JavaScript Object.
async interface.validate() Checks the datatypes and properties of the document. Returns true if valid, false if not.