javascript - 在 Windows 上指定 Sequelize sqlite 路径

标签 javascript node.js sqlite electron sequelize.js

我一直在 Linux 中使用 Sequelize 和 sqlite3 开发一个 Electron 应用程序,一切都运行良好。我像这样连接到数据库:

new Sequelize("sqlite:" + myPath);

其中 myPath 的形式为“/home/.../someDB.db”

但是,我尝试在 Windows 上运行我的项目,但遇到了连接数据库的问题。

如果我使用“someDB.DB”作为 myPath,我可以连接到数据库,但是当 myPath 是“C:...\someDB.db”形式的绝对路径时,我会收到错误:

C:\projectPath\node_modules\bluebird\js\release\debuggability.js:868 Unhandled rejection SequelizeConnectionError: SQLITE_CANTOPEN: unable to open database file at Database.connections.(anonymous function).lib.Database.err (C:\projectPath\node_modules\sequelize\lib\dialects\sqlite\connection-manager.js:66:63) printWarning @ C:\projectPath\node_modules\bluebird\js\release\debuggability.js:868 formatAndLogError @ C:\projectPath\node_modules\bluebird\js\release\debuggability.js:593 fireRejectionEvent @ C:\projectPath\node_modules\bluebird\js\release\debuggability.js:618 Promise._notifyUnhandledRejection @ C:\projectPath\node_modules\bluebird\js\release\debuggability.js:64 (anonymous) @ C:\projectPath\node_modules\bluebird\js\release\debuggability.js:43 setTimeout (async) Promise._ensurePossibleRejectionHandled @ C:\projectPath\node_modules\bluebird\js\release\debuggability.js:42 Promise._reject @ C:\projectPath\node_modules\bluebird\js\release\promise.js:658 Promise._settlePromise @ C:\projectPath\node_modules\bluebird\js\release\promise.js:584 Promise._settlePromise0 @ C:\projectPath\node_modules\bluebird\js\release\promise.js:614 Promise._settlePromises @ C:\projectPath\node_modules\bluebird\js\release\promise.js:689 Async._drainQueue @ C:\projectPath\node_modules\bluebird\js\release\async.js:133 Async._drainQueues @ C:\projectPath\node_modules\bluebird\js\release\async.js:143 Async.drainQueues @ C:\projectPath\node_modules\bluebird\js\release\async.js:17 Async Call schedule @ C:\projectPath\node_modules\bluebird\js\release\schedule.js:18 Async._queueTick @ C:\projectPath\node_modules\bluebird\js\release\async.js:152 AsyncSettlePromises @ C:\projectPath\node_modules\bluebird\js\release\async.js:88 Promise._reject @ C:\projectPath\node_modules\bluebird\js\release\promise.js:656 Promise._settlePromise @ C:\projectPath\node_modules\bluebird\js\release\promise.js:566 Promise._settlePromise0 @ C:\projectPath\node_modules\bluebird\js\release\promise.js:614 Promise._settlePromises @ C:\projectPath\node_modules\bluebird\js\release\promise.js:689 Async._drainQueue @ C:\projectPath\node_modules\bluebird\js\release\async.js:133 Async._drainQueues @ C:\projectPath\node_modules\bluebird\js\release\async.js:143 Async.drainQueues @ C:\projectPath\node_modules\bluebird\js\release\async.js:17 Async Call schedule @ C:\projectPath\node_modules\bluebird\js\release\schedule.js:18 Async._queueTick @ C:\projectPath\node_modules\bluebird\js\release\async.js:152 AsyncSettlePromises @ C:\projectPath\node_modules\bluebird\js\release\async.js:88 Promise._reject @ C:\projectPath\node_modules\bluebird\js\release\promise.js:656 Promise._settlePromise @ C:\projectPath\node_modules\bluebird\js\release\promise.js:566 Promise._settlePromise0 @ C:\projectPath\node_modules\bluebird\js\release\promise.js:614 Promise._settlePromises @ C:\projectPath\node_modules\bluebird\js\release\promise.js:689 Async._drainQueue @ C:\projectPath\node_modules\bluebird\js\release\async.js:133 Async._drainQueues @ C:\projectPath\node_modules\bluebird\js\release\async.js:143 Async.drainQueues @ C:\projectPath\node_modules\bluebird\js\release\async.js:17 Async Call schedule @ C:\projectPath\node_modules\bluebird\js\release\schedule.js:18 Async._queueTick @ C:\projectPath\node_modules\bluebird\js\release\async.js:152 AsyncSettlePromises @ C:\projectPath\node_modules\bluebird\js\release\async.js:88 Promise._reject @ C:\projectPath\node_modules\bluebird\js\release\promise.js:656 Promise._rejectCallback @ C:\projectPath\node_modules\bluebird\js\release\promise.js:474 (anonymous) @ C:\projectPath\node_modules\bluebird\js\release\promise.js:486 connections.(anonymous function).lib.Database.err @ C:\projectPath\node_modules\sequelize\lib\dialects\sqlite\connection-manager.js:66

我应该如何在 Windows 上使用 Sequelize 连接到 sqlite 数据库?

最佳答案

我意识到解决方案只是使用更详细的构造函数:

new Sequelize('', '', '', {
        dialect: 'sqlite',
        storage: myPath
      });

关于javascript - 在 Windows 上指定 Sequelize sqlite 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51124850/

相关文章:

javascript - 如何将 OpenLayers 与 react-starter-kit 一起使用?

node.js - AWS Lambda 函数在 context.fail 之后继续运行一段时间

python:合并 SQLITE 表的列表列表

javascript - 一一循环ajax请求并一一显示结果?

javascript - 字体大小变化问题

javascript - AngularJS + simpleCart 问题显示购物车内容直到添加项目

javascript - 我可以使用 Array.prototype.map 的模来每 3 个索引插入新行吗?

javascript - 将自定义参数/查询/ header 添加到 Google Cloud 函数

sqlite - SQL - 删除具有空值的重复项 WITHOUT row_number

php - 错误 : file is encrypted or is not a database