You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constconfig=require("./../../config")constmysql=require("mysql")//配置数据库参数constpool=mysql.createPool({host : config["DB_HOST"],user : config["DB_USER"],password : config["DB_PASSWORD"],database : config["DB_DATABASE"]});//数据库基本操作方法constquery=function(sql,values,callback){pool.getConnection(function(err,conn){if(err){callback(err,false)}else{varquerys=conn.query(sql,values,function(err,rows){if(err){callback(err,false)}else{callback(null,rows)}});}});}//数据库对外操作类classDatabaseUtil{//建表方法createTable(sql,callback){query(sql,[],callback)}//根据id查找数据findDataById(table,id,callback){let_sql="select * from ?? where id = ? "query(_sql,[table,id,start,end],callback)}//分页查找数据findDataByPage(table,start,end,callback){let_sql="select * from ?? limit ? , ?"query(_sql,[table,start,end],callback)}//插入数据insertData(table,values,callback){let_sql="insert into ?? set ?"query(_sql,[table,values],callback)}//更新数据updateData(table,values,id,callback){let_sql="update ?? set ? where id = ?"query(_sql,[table,values,id],callback)}//删除数据deleteDataById(table,id,callback){let_sql="delete from ?? where id = ?"query(_sql,[table,id],callback)}}module.exports=DatabaseUtil
ES6+thunkify封装和使用 node.js的mysql模块
利用ES6 class 语法重新封装mysql模块
databaseUtil.js
利用thunkify封装方法并使用
The text was updated successfully, but these errors were encountered: