Укажите Sequelize sqlite path в Windows - PullRequest
0 голосов
/ 01 июля 2018

Я разрабатывал приложение Electron в Linux, используя Sequelize с sqlite3, и все отлично работает. Я подключаюсь к базам данных так:

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 Необработанный отказ 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 \ обещание.js: 658 Promise._settlePromise @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.js: 584 Promise._settlePromise0 @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.js: 614 Promise._settlePromises @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.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 Асинхронный вызов 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 \ обещание.js: 656 Promise._settlePromise @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.js: 566 Promise._settlePromise0 @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.js: 614 Promise._settlePromises @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.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 Асинхронный вызов 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 \ обещание.js: 656 Promise._settlePromise @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.js: 566 Promise._settlePromise0 @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.js: 614 Promise._settlePromises @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.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 Асинхронный вызов schedule @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ schedule.js: 18 Async._queueTick @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ async.js: 152AsyncSettlePromises @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ async.js: 88 Promise._reject @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.js: 656 Promise._rejectCallback @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.js: 474 (анонимно) @ C: \ projectPath \ node_modules \ bluebird \ js \ release \ обещание.js: 486 соединения. (анонимная функция) .lib.Database.err @ C: \ projectPath \ node_modules \ sequelize \ lib \ dialects \ sqlite \ connection-manager.js: 66

Как мне подключиться к базам данных sqlite с помощью Sequelize в Windows?

1 Ответ

0 голосов
/ 01 июля 2018

Я понял, что решение было просто использовать более подробный конструктор:

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