2023-06-20 22:34:27 +08:00
|
|
|
const sqlite = require("sqlite3")
|
2023-06-28 21:11:21 +08:00
|
|
|
const path = require("path");
|
|
|
|
const { cwd } = require("process");
|
|
|
|
let p = path.join(cwd(),"/db/database.db")
|
|
|
|
database = new sqlite.Database(p, function(err) {
|
2023-06-20 22:34:27 +08:00
|
|
|
if (err) throw err;
|
|
|
|
});
|
|
|
|
|
|
|
|
function run(){
|
2023-06-28 21:11:21 +08:00
|
|
|
let args = arguments
|
|
|
|
console.log(args)
|
|
|
|
return new Promise((res,err)=>{
|
|
|
|
database.run(...args,(error)=>{
|
|
|
|
if(error){
|
|
|
|
err(error)
|
|
|
|
}else{
|
|
|
|
res("添加成功")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2023-06-20 22:34:27 +08:00
|
|
|
}
|
|
|
|
|
2023-06-28 21:11:21 +08:00
|
|
|
function getAll(sql){
|
|
|
|
let args = arguments
|
|
|
|
return new Promise((res,err)=>{
|
|
|
|
database.all(...args,function (error,data){
|
|
|
|
if(error){
|
|
|
|
err(error)
|
|
|
|
}else{
|
|
|
|
res(data)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2023-06-20 22:34:27 +08:00
|
|
|
|
|
|
|
module.exports = {
|
2023-06-28 21:11:21 +08:00
|
|
|
run,
|
|
|
|
getAll
|
2023-06-20 22:34:27 +08:00
|
|
|
}
|