Giter Site home page Giter Site logo

rednexie / nedb-odm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from levg34/typescript-nedb-orm

1.0 0.0 0.0 184 KB

ODM for @seald-io/nedb written in TypeScript

Home Page: https://www.npmjs.com/package/nedb-odm

License: GNU General Public License v3.0

nedb-odm's Introduction

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

Configuration

Store databases in another directory:

ODM.path = "./ODM";

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.

nedb-odm's People

Contributors

levg34 avatar rednexie avatar atorber avatar

Stargazers

 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.