在Windows上指定Sequelize sqlite路径

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Windows上指定Sequelize sqlite路径相关的知识,希望对你有一定的参考价值。

我一直在使用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数据库?

答案

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

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

以上是关于在Windows上指定Sequelize sqlite路径的主要内容,如果未能解决你的问题,请参考以下文章

Windows上DVWA和sqli-labs部署

Windows上DVWA和sqli-labs部署

SQLite 的 Sequelize-auto

使用 Sequelize (NodeJS) 而不是 * 指定特定字段

Sequelize - 我必须在模型和查询中都指定“as”吗?

sequelize模型