kmodel

Object-oriented model based on mongoose

npm install kmodel
14 downloads in the last week
21 downloads in the last month

kmodel

Installation

$ npm install kmodel

Quick Start

var k = require("kmodel");

k.connect();

var User = k.create({
    username: "string",
    password: "string",
    nickname: "string"
}, "User");

var query = function(){
    User.query({}, function(err, users){
        console.log(users);// 
    });
};

User.insertOne({
    username: "aki",
    password: "aki",
    nickname: "eeee"
},query);

Extendable

// for User
k.extend(User, "login", function(name, password, callback){
    this.queryOne({username: name, password: password}, function(err, instance){
        callback(instance || err);
    });
});

User.login("aki", "awki", function(user){
    if(user) console.log(user.username+" is succes sign in");
    else console.log("failed");
});
// for Class 
k.all("names", function(username, callback){
    this.query({username:username}, callback);
});

User.names("aki", function(err, users){
    console.log(users.length)
});
npm loves you