monpy-db
v0.1.2
Published
RDB Entity framework
Downloads
4
Readme
monpy-db
Installation
$ npm install monpy-db
Example
Model
var db = require('monpy-db')('mysql');
function User(){
db.BaseEntity.apply(this, arguments);
}
db.inherits(User, db.BaseEntity);
Use
var db = require('monpy-db')('mysql'),
co = require('co'),
config = {
pool: 5,
host: 'localhost',
user: 'test',
password: 'password',
database: 'test_db'
};
var model = new User();
var user = {
name: 'monpy',
comment: 'hello',
created_at: new Date()
};
co(function *(){
// DataBase Connect
db.connect(config);
// INSERT
var ret = yield model.insert(user);
// var ret = yield model.save(user);
var userId = ret.insertId;
var user = yield model.getById(userId);
console.log(user);
// UPDATE
user.updated_at = new Date();
var ret = yield model.update(user);
// var ret = yield model.save(user);
// DataBase Disconnect
db.end();
});