简体   繁体   English

electron 生产模式下的 SQLITE 数据库文件存储在哪里?

[英]Where to store SQLITE db file in electron production mode?

I'm building portable node js server using electron.我正在使用 electron 构建便携式节点 js 服务器。 I'm using SQLITE database for storing data.我正在使用 SQLITE 数据库来存储数据。

In development mode I put database file test.db in directory where is my Main.js file and everything is running perfectly.在开发模式下,我将数据库文件test.db放在Main.js文件所在的目录中,并且一切运行良好。

When I deploy my app electron-builder --mac and run it, it cannot access to database file.当我部署我的应用程序electron-builder --mac并运行它时,它无法访问数据库文件。 (File not found) (文件未找到)

So my question is where should I store my test.db file so it's working both in development and production mode?所以我的问题是我应该在哪里存储我的test.db文件,以便它在开发和生产模式下都可以工作?

Is it possible to embed db file somewhere while creating application for win/mac/linux so end user doesn't need to take care where is db file located?是否可以在为 win/mac/linux 创建应用程序时将 db 文件嵌入某处,以便最终用户不需要注意 db 文件的位置?

Thank you谢谢

you can store it into application data,您可以将其存储到应用程序数据中,
const dbPath = path.join(app.getPath("userData"), "sample.db")

Check out docs here, https://www.electronjs.org/docs/api/app#appgetpathname在此处查看文档, https://www.electronjs.org/docs/api/app#appgetpathname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM