在Windows上指定Sequelize sqlite路径

问题描述 投票:0回答:1

我一直在使用Sequelize和sqlite3在Linux上开发一个Electron应用程序,一切都很棒。我连接到这样的数据库:

new Sequelize("sqlite:" + myPath);

myPath的形式为'/home/.../someDB.db'

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

如果我对myPath使用'someDB.DB',我可以连接到db,但是当myPath是'C:... \ someDB.db'形式的绝对值时,我收到一个错误:

C:\ projectPath \ node_modules \ bluebird \ js \ release \ debuggability.js:868未处理拒绝SequelizeConnectionError:SQLITE_CANTOPEN:无法在Database.connections打开数据库文件。(匿名函数).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(匿名)@ 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:\ pr ojectPath \ 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异步调用计划@ 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._settleP romises @ 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._dr ainQueues @ 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 (匿名)@ C:\ projectPath \ node_modules \ bluebird \ js \ release \ promise.js:486个连接。(匿名函数).lib.Database.err @ C:\ projectPath \ node_modules \ sequelize \ lib \ dialects \ sqlite \连接manager.js:66

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

javascript node.js sqlite electron sequelize.js
1个回答
1
投票

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

new Sequelize('', '', '', {
        dialect: 'sqlite',
        storage: myPath
      });
© www.soinside.com 2019 - 2024. All rights reserved.