init pages service
This commit is contained in:
1 parent
d3539b6d62
commit
92655b6b7c
11 files changed
+1798
No files matched your search
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
*
|
||||
* @authors Tony.Deng (dengtongyu123@163.com)
|
||||
* @date 2017-07-21 10:54:14
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
const mysql = require('mysql');
|
||||
|
||||
let mysqlConfig = {
|
||||
host : 'localhost',
|
||||
user : 'picture',
|
||||
password : 'tony112403',
|
||||
port: '3306',
|
||||
database : 'picture'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
//获取connection
|
||||
getConnection:function() {
|
||||
|
||||
let connection = mysql.createConnection(mysqlConfig);
|
||||
|
||||
return connection;
|
||||
},
|
||||
|
||||
//读取数据
|
||||
getPictureList:function(sortField,start,number,callback){
|
||||
let connection = mysql.createConnection(mysqlConfig);
|
||||
connection.connect();
|
||||
|
||||
let sql = 'select * from beauty order by '+sortField+' desc limit '+start+','+number+';';
|
||||
//查
|
||||
connection.query(sql,function (err, result) {
|
||||
if(err){
|
||||
console.log('[SELECT ERROR] - ',err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if(callback) callback(result);
|
||||
});
|
||||
|
||||
connection.end();
|
||||
},
|
||||
|
||||
//插入数据
|
||||
insertDataToBeauty:function(elementId,fileName,imgsrc,gifFileName,orgUrl,connection){
|
||||
let date = new Date();
|
||||
|
||||
//在mysql中增加记录
|
||||
let addSql = 'insert into beauty(element_id,local_image_url,src_image_url,local_gif_url,src_gif_url,record_time) VALUES(?,?,?,?,?,?)';
|
||||
let addSqlParams = [elementId,'/'+fileName,imgsrc,gifFileName?('/'+gifFileName):null,orgUrl,date];
|
||||
connection.query(addSql,addSqlParams,function (err, result) {
|
||||
if(err){
|
||||
console.log('[INSERT ERROR] - ',err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('--------------------------INSERT----------------------------');
|
||||
//console.log('INSERT ID:',result.insertId);
|
||||
console.log('INSERT ID:',result);
|
||||
console.log('-----------------------------------------------------------------\n\n');
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user