1: 增加db,名称 my.db
https://www.sqlite.org/download.html
您需要下载 sqlite-tools-win32-*.zip 和 sqlite-dll-win32-*.zip 压缩文件
CREATE TABLE TaoCan(
ID INT PRIMARY KEY NOT NULL,
Phone varchar(20),
Result varchar(200) ,
);
2:npm install sqlite3
3:flow
3.1 save to db every 1000
INSERT INTO TaoCan(Phone,Result) VALUES ()
3.2 download to excel
3.3 delete data
4:nodejs 封装sqlite
const sqlite3 = require('sqlite3').verbose()
var db
exports.db = db
exports.open=function(path) {
return new Promise(function(resolve) {
this.db = new sqlite3.Database(path,
function(err) {
if(err) reject("Open error: "+ err.message)
else resolve(path + " opened")
}
)
})
}
// any query: insert/delete/update
exports.run=function(query) {
return new Promise(function(resolve, reject) {
this.db.run(query,
function(err) {
if(err) reject(err.message)
else resolve(true)
})
})
}
// first row read
exports.get=function(query, params) {
return new Promise(function(resolve, reject) {
this.db.get(query, params, function(err, row) {
if(err) reject("Read error: " + err.message)
else {
resolve(row)
}
})
})
}
// set of rows read
exports.all=function(query, params) {
return new Promise(function(resolve, reject) {
if(params == undefined) params=[]
this.db.all(query, params, function(err, rows) {
if(err) reject("Read error: " + err.message)
else {
resolve(rows)
}
})
})
}
// each row returned one by one
exports.each=function(query, params, action) {
return new Promise(function(resolve, reject) {
var db = this.db
db.serialize(function() {
db.each(query, params, function(err, row) {
if(err) reject("Read error: " + err.message)
else {
if(row) {
action(row)
}
}
})
db.get("", function(err, row) {
resolve(true)
})
})
})
}
exports.close=function() {
return new Promise(function(resolve, reject) {
this.db.close()
resolve(true)
})
}
From <https://www.jb51.net/article/156253.htm>
https://www.jianshu.com/p/33b132078b05
https://www.codeleading.com/article/17874614799/
https://www.runoob.com/sqlite/sqlite-insert.html