Commit 25491466 authored by Scott Sun's avatar Scott Sun

scott

parent 918042f1
......@@ -2,19 +2,15 @@ var fs = require('fs');
var parser = require('topsin.parser');
var db = require('topsin.database');
// 获取的数据
// 获取csv的数据
function getCsvArr(path){
var file = fs.openFile(path); // 获取文件流
file.setCodec('UTF-8'); // 设置编码
var csvstr = file.readAll(); // 获取csv字符串
var csvdata = parser.parseCsvStr(csvstr); // 转变为数组
// csvdata[0] = csvdata[0].map(function(v){ // 第一行字段矫正
// return v.split('\n').join('');
// });
csvdata.shift();
csvdata.shift(); // 除去第一行
return csvdata;
}
// 获取的表的数据
var res = getCsvArr('./confirmation-201912270900(1).csv');
// 创建数据库连接
......@@ -31,7 +27,7 @@ db.addConnection({
function Query(db,table,connectName){
this.db = db;
this.table = table;
this.normal = function(callback){ // 自定义配置
this.normal = function(callback){ // 自定义
return this.db.query(connectName,callback);
}
this.getAllData = function(){ // 获取所有数据
......@@ -50,7 +46,6 @@ function Query(db,table,connectName){
});
}
}
// 生成操作数据库实例
var query = new Query(db,'sec_production_order_confirmation_2','Scott_PMO_TRAINING');
// 获取数据库的字段
......@@ -64,7 +59,7 @@ function getkeyCount(){
var res = 0;
for(var keycount in list[0]){
if(list[0][keycount] !== undefined){
res++
res++;
}
}
return res-1
......@@ -109,16 +104,15 @@ if (list.length !== res.length){
);
})
}
// console.log(query.normal(function(q){
// return q.selectMap({
// table:'sec_production_order_confirmation_2',
// field: '*',
// field_format:{tags:'array', attr_data:'json'},
// limit: 1,
// order:'id DESC'
// });
// }))
console.log(query.normal(function(q){
return q.selectMap({
table:'sec_production_order_confirmation_2',
field: '*',
field_format:{tags:'array', attr_data:'json'},
limit: 1,
order:'id DESC'
});
}))
// console.log(res[res.length-1])
......@@ -35,5 +35,5 @@
## 2019-12-27
* postgreSql
* topsin.database topsin.sqlquery 数据库操作
* 需求:读取excel数据 存入数据库
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment