kmodel
v2.3.6
Published
co mongoose
Downloads
49
Readme
kmodel
Installation
npm install kmodel
Quick Start
var KModel = require("kmodel");
var k = new KModel("mongodb://ip:port/dbname", __dirname+"/models/");
var k2 = new KModel("mongodb://ip:port/dbname", __dirname+"/models/");
mkdir ./models
touch ./models/User.js
User.js
var User = k.create({
username: "string",
password: "string",
nickname: "string"
}, "User");
with koa
var User = k.load("User");
router.get('/user/:id', function *() {
var id = this.params.id;
var result = yield User.exec({
method: "find",
limit: 20
});
this.body = yield User.find({_id:id});
});
// Normal Functions With Mongoose Model
User.model.find().exec();
// Generator Functions With KModel
yield User.exec({
method: "find",
skip: 10,
limit: 20,
sort: {ctime: -1},
select: "username password"
});
Multi-Database
var k1 = new KModel("mongodb://ip:port/dbname", __dirname+"/models/");
var k2 = new KModel("mongodb://ip:port/dbname", __dirname+"/models/");