[英]how to connect sqlite3 with electron js
please guide me through a full process, that I connect my electron app with sqlite3.请指导我完成一个完整的过程,将我的电子应用程序与 sqlite3 连接起来。 because I have a lot of issues occurring in my electron js.
因为我的电子 js 中发生了很多问题。 Thank you.
谢谢你。
Main.js:主要.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:渲染器.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)
By far the easiest way to use SQLite with electron is with electron-builder.到目前为止,将 SQLite 与电子一起使用的最简单方法是使用电子生成器。
First, add a postinstall step in your package.json:首先,在 package.json 中添加安装后步骤:
"scripts": {
"postinstall": "install-app-deps"
...
}
and then install the necessary dependencies and build:然后安装必要的依赖项并构建:
npm install --save-dev electron-builder
npm install --save sqlite3
npm run postinstall
electron-builder will build the native module for your platform, with the correct name for the Electron binding;电子构建器将为您的平台构建本机模块,并为电子绑定提供正确的名称; and you can then require it in code as normal.
然后你可以像往常一样在代码中要求它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.