Reputation: 153
I've been developing an Electron app in Linux using Sequelize with sqlite3, and everything works great. I connect to databases like this:
new Sequelize("sqlite:" + myPath);
Where myPath has been in the form of '/home/.../someDB.db'
However, I tried running my project on Windows and ran into a problem connecting to the db.
I can connect to the db if I use 'someDB.DB' for myPath, but when myPath is an absolute in the form 'C:...\someDB.db' I get an error:
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
How should I go about connecting to sqlite databases with Sequelize on Windows?
Upvotes: 2
Views: 2141
Reputation: 153
I realized the solution was just to use the more verbose constructor:
new Sequelize('', '', '', {
dialect: 'sqlite',
storage: myPath
});
Upvotes: 5