首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将sqlite3与电子js连接

如何将sqlite3与电子js连接
EN

Stack Overflow用户
提问于 2021-11-03 14:56:11
回答 1查看 140关注 0票数 0

请指导我通过一个完整的过程,我连接我的电子应用程序与sqlite3。因为我的电子js中有很多问题。谢谢。

Main.js:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2021-11-03 15:01:47

到目前为止,与电子一起使用SQLite的最简单的方法是使用电子生成器。

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

代码语言:javascript
复制
"scripts": {
   "postinstall": "install-app-deps"
   ...
}

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

代码语言:javascript
复制
npm install --save-dev electron-builder
npm install --save sqlite3
npm run postinstall

电子构建器将为您的平台构建本机模块,并为电子绑定提供正确的名称;然后,您可以按照正常的代码要求它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69827056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档