UNPKG

nyx_server

Version:

Node内容发布

73 lines (62 loc) 1.35 kB
var Promise = require("bluebird") function Connection(connectParams , pool){ this.pool = pool; this.connection = this._create(connectParams); this.lastUseTime = new Date(); } /** * 启动一个事务 * @param fn 事务启动成功后的回调事件 */ Connection.prototype.beginTransaction = function(fn){ this.connection.beginTransaction(fn); }; /** * 提交一个事务 * @param fn 提交后的回调事件 */ Connection.prototype.commit = function(fn){ this.connection.commit(fn); }; /** * 回滚一个事务 * @param fn 回滚后的回调事件 */ Connection.prototype.rollback = function(fn){ this.connection.rollback(fn); }; /** * 释放一个连接 */ Connection.prototype.release = function(fn){ if(this.pool){ this.pool.release(this , fn); }else{ this.end(fn); } }; /** * 关闭一个连接 */ Connection.prototype.close = function(fn){ if(this.pool){ this.pool.close(this , fn); } this.end(fn); }; Connection.prototype.end = function(fn){ this.connection.end(fn); }; /** * 执行一个sql语句 * @param {String}sql * @param {Array}values sql绑定的数据 */ Connection.prototype.query = function(sql , values){ this.lastUseTime = new Date(); return this.connection.query(sql , values); }; Connection.prototype.vaild = function(){ return Promise.resolve(true); }; module.exports = Connection;