Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Mysql = require('mysql').createClient({
- host: 'ensky.tw',
- user: 'comic',
- password: 'enskya04cj84j;3',
- // port: '/tmp/mysql.sock', // 使用sock連線
- port: '3306',
- database: 'comic'
- });
- var DB = function(){
- this.cleanup = function(){
- this.ignore = false;
- }
- this.cleanup();
- };
- DB.prototype = Mysql;
- DB.Method('Param', function(param){
- var keys = [],
- vals = [],
- ques = [];
- for(x in param){
- keys.push(x);
- vals.push(param[x]);
- ques.push('?');
- }
- return {keys:keys, vals:vals, ques:ques};
- });
- DB.Method('Insert', function(table, param, cb){
- cb = cb || function(){};
- self = this;
- var myparam = self.Param(param);
- var ignore = this.ignore == true ? 'IGNORE ' : '';
- var sql = 'INSERT '+ ignore +'INTO `'+ table +'` (`'+ myparam.keys.join('`,`') +'`) VALUES ('+ myparam.ques.join(',') +')';
- Mysql.query(sql, myparam.vals, cb);
- });
- DB.Method('Replace', function(table, param, cb){
- cb = cb || function(){};
- self = this;
- var myparam = self.Param(param);
- var sql = 'REPLACE INTO `'+ table +'` (`'+ myparam.keys.join('`,`') +'`) VALUES ('+ myparam.ques.join(',') +')';
- Mysql.query(sql, myparam.vals, cb);
- });
- DB.Method('Insert', function(table, param, cb){
- cb = cb || function(){};
- self = this;
- var myparam = self.Param(param);
- var ignore = this.ignore == true ? 'IGNORE ' : '';
- var sql = 'INSERT '+ ignore +'INTO `'+ table +'` (`'+ myparam.keys.join('`,`') +'`) VALUES ('+ myparam.ques.join(',') +')';
- Mysql.query(sql, myparam.vals, cb);
- });
- module.exports = new DB();
Add Comment
Please, Sign In to add comment