【问题标题】:how to connect sqlite3 with electron js如何将 sqlite3 与电子 js 连接起来
【发布时间】:2021-12-17 23:06:33
【问题描述】:

请指导我完成一个完整的过程,我将我的电子应用程序与 sqlite3 连接起来。 因为我的电子 js 中出现了很多问题。 谢谢。

Main.js:

const{app,BrowserWindow,ipcMain}=require("electron");
app.on("ready",createWindow);

const si = require("systeminformation");
require("electron-reload")(__dirname);

function createWindow()
{
    const window = new BrowserWindow({
        width: 800,
        height:600,
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
        }

    });
    window.webContents.openDevTools();
    window.loadFile(__dirname+ "/index.html");

}

ipcMain.on("get-cpu-usage",(events,args)=>{

console.log(args);
});

renderer.js:

const{ipcRender} = require("electron")

const os=require("os");
const cpuName=document.getElementById("cpu-name");
const cpuCores =document.getElementById("cores");
const cpuUsage =document.getElementById("cpu-usage");


const cpus=os.cpus();
cpuName.innerText=`CPU: ${cpus[0].model}`;
cpuCores,innerText=`Cores Available: ${cpus.length}`;

setInterval(() =>{
    console.log("sending message to get cpu stats")
    ipcRender.send("get-cpu-usage", "Hello sheraz The render process")
},2000)

【问题讨论】:

  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。

标签: node.js sqlite electron node-sqlite3


【解决方案1】:

到目前为止,将 SQLite 与 electron 结合使用的最简单方法是使用 electron-builder。

首先,在你的 package.json 中添加一个 postinstall 步骤:

"scripts": {
   "postinstall": "install-app-deps"
   ...
}

然后安装必要的依赖并构建:

npm install --save-dev electron-builder
npm install --save sqlite3
npm run postinstall

electron-builder 将为您的平台构建本机模块,并为 Electron 绑定使用正确的名称;然后你可以像往常一样在代码中要求它。

【讨论】:

  • 当我安装 electron-builder 然后保存 sqlite3 最后我安装 postinstall 时出现错误。PS C:\Users\Muhammad Sheraz\electron-quick-start> npm run postinstall npm ERR!缺少脚本:安装后 npm ERR!可以在以下位置找到此运行的完整日志:npm ERR! C:\Users\Muhammad Sheraz\AppData\Roaming\npm-cache_logs\2021-11-03T15_16_19_166Z-debug.log
猜你喜欢
  • 2019-04-16
  • 2020-11-14
  • 2016-10-13
  • 2023-01-25
  • 2015-12-06
  • 2020-05-17
  • 2017-10-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多