Skip to content

Commit c3e608b

Browse files
soryy708sdepold
andauthored
fix(sqlite): fix wrongly overwriting storage if empty string (#13376)
* fix(sqlite): fix wrongly overwriting storage if empty string Empty string in SQLite3 means anonymous disk-based db, but sequelize overwrited it with :memory: Closes #13375 * fix(sqlite): fix node<10 chokes on nullish coalescing operator * refactor(sqlite): remove unnecessary parentheses around expression Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com>
1 parent dc67dc9 commit c3e608b

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

lib/dialects/sqlite/connection-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ConnectionManager extends AbstractConnectionManager {
4545
async getConnection(options) {
4646
options = options || {};
4747
options.uuid = options.uuid || 'default';
48-
options.storage = this.sequelize.options.storage || this.sequelize.options.host || ':memory:';
48+
options.storage = this.sequelize.options.storage !== null && this.sequelize.options.storage !== undefined ? this.sequelize.options.storage : this.sequelize.options.host || ':memory:';
4949
options.inMemory = options.storage === ':memory:' ? 1 : 0;
5050

5151
const dialectOptions = this.sequelize.options.dialectOptions;

test/support.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const Support = {
113113
sequelizeOptions.native = true;
114114
}
115115

116-
if (config.storage) {
116+
if (config.storage || config.storage === '') {
117117
sequelizeOptions.storage = config.storage;
118118
}
119119

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const chai = require('chai'),
4+
expect = chai.expect,
5+
Support = require('../../support'),
6+
Sequelize = Support.Sequelize,
7+
dialect = Support.getTestDialect(),
8+
sinon = require('sinon');
9+
10+
if (dialect === 'sqlite') {
11+
describe('connectionManager', () => {
12+
describe('getConnection', () => {
13+
it('Should respect storage=\'\'', () => {
14+
// storage='' means anonymous disk-based database
15+
const sequelize = new Sequelize('', '', '', { dialect: 'sqlite', storage: '' });
16+
sinon.stub(sequelize.connectionManager, 'lib').value({
17+
Database: function FakeDatabase(_s, _m, cb) {
18+
cb();
19+
return {};
20+
}
21+
});
22+
sinon.stub(sequelize.connectionManager, 'connections').value({ default: { run: () => {} } });
23+
const options = {};
24+
sequelize.dialect.connectionManager.getConnection(options);
25+
expect(options.storage).to.be.equal('');
26+
});
27+
});
28+
});
29+
}

0 commit comments

Comments
 (0)