monpy-db
RDB Entity framework
Last updated 3 years ago by monpoco .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install monpy-db 
SYNC missed versions from official npm registry.

monpy-db Build Status npm version

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();
});

Document

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |