【问题标题】:What is the proper way to handle SQLite3 queries in an electron app?在电子应用程序中处理 SQLite3 查询的正确方法是什么?
【发布时间】:2019-11-22 00:49:43
【问题描述】:

我正在尝试在我的 Electron 应用程序中实现 SQLite3,以便在应用程序关闭时保存用户首选项(Electron 的“关闭”事件)和来自 API 的用户数据。此 API 数据可以随时从脚本的各个部分到达,需要保存。有问题的错误是 sqlite_busy: database is locked

我已经尝试将 SQLite3 的方法包装在一个承诺中,以便在单独的模块中与“async/await”一起使用,但这只能让我到目前为止。

  • 如何实现它以保存 API 数据而不会遇到“锁定”问题?
  • 如果应用在查询完成之前崩溃或关闭怎么办?
  • 是否需要查询队列
// const queue = [];
// push query to the queue
// loop to check if the queue has a query to handle
// execute the query and remove it from the queue

【问题讨论】:

    标签: javascript node.js sqlite electron


    【解决方案1】:

    我正在使用 Knex 库 来管理 SQLite 数据库以及包括迁移在内的所有操作。您可以在这里获取所有信息表https://knexjs.org/

    至于database is locked issue,您可以使用 Transaction 方法来保持与 Knex 的并发性,这可以帮助您克服这种情况。您可以查看有关如何实现事务查询的更多详细信息。 https://knexjs.org/#Builder-transacting

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-12
      相关资源
      最近更新 更多