38 Star 463 Fork 256

CcSimple/electron-hiprint

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
database.js 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
const { app } = require("electron");
const sqlite3 = require("sqlite3").verbose();
const path = require("path");
// 创建或打开数据库
let dbPath = path.join(__dirname, "database.sqlite");
if (app.isPackaged) {
dbPath = path.join(app.getAppPath(), "../", "database.sqlite");
}
const db = new sqlite3.Database(dbPath, (err) => {
if (err) {
console.error("Could not connect to database", err);
} else {
console.log("Connected to database");
}
});
// 创建打印日志记录表
db.serialize(() => {
db.run(`
CREATE TABLE IF NOT EXISTS print_logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
socketId TEXT,
clientType TEXT,
printer TEXT,
templateId TEXT,
data TEXT,
pageNum INTEGER,
status TEXT,
errorMessage TEXT
)
`);
// 添加新的可选字段 rePrintAble,默认值为 1
db.run(
`
ALTER TABLE print_logs ADD COLUMN rePrintAble INTEGER DEFAULT 1;
`,
(err) => {
if (err && !err.message.includes("duplicate column")) {
console.error("添加新字段时出错:", err);
}
},
);
});
module.exports = db;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/CcSimple/electron-hiprint.git
git@gitee.com:CcSimple/electron-hiprint.git
CcSimple
electron-hiprint
electron-hiprint
master

搜索帮助