0.0.3 • Published 10 months ago

sagitarius v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Introduction

Minimal, easy to use, fast Object Document Mapping(ODM) library for NeDB. Supports type-checking and schema validation.

Installation

npm install sagitarius
yarn add sagitarius
pnpm add sagitarius

Quick 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.

Model Methods

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

11 months ago

0.0.0

2 years ago