不要怂,就是干,撸起袖子干!

Commit fa587acc by Justin Kalland Committed by Sushant

feat: pass uri query parameters to dialectOptions (#10025)

1 parent fcd07efb
...@@ -105,7 +105,7 @@ class Sequelize { ...@@ -105,7 +105,7 @@ class Sequelize {
config = {}; config = {};
options = username || {}; options = username || {};
const urlParts = url.parse(arguments[0]); const urlParts = url.parse(arguments[0], true);
options.dialect = urlParts.protocol.replace(/:$/, ''); options.dialect = urlParts.protocol.replace(/:$/, '');
options.host = urlParts.hostname; options.host = urlParts.hostname;
...@@ -131,6 +131,13 @@ class Sequelize { ...@@ -131,6 +131,13 @@ class Sequelize {
if (authParts.length > 1) if (authParts.length > 1)
config.password = authParts.slice(1).join(':'); config.password = authParts.slice(1).join(':');
} }
if (urlParts.query) {
if (options.dialectOptions)
_.assign(options.dialectOptions, urlParts.query);
else
options.dialectOptions = urlParts.query;
}
} else { } else {
// new Sequelize(database, username, password, { ... options }) // new Sequelize(database, username, password, { ... options })
options = options || {}; options = options || {};
......
...@@ -153,5 +153,30 @@ describe('Sequelize', () => { ...@@ -153,5 +153,30 @@ describe('Sequelize', () => {
expect(config.port).to.equal(port); expect(config.port).to.equal(port);
}); });
it('should pass query string parameters to dialectOptions', () => {
const sequelize = new Sequelize('mysql://example.com:9821/dbname?ssl=true');
const dialectOptions = sequelize.config.dialectOptions;
expect(dialectOptions.ssl).to.equal('true');
});
it('should merge query string parameters to options', () => {
const sequelize = new Sequelize('mysql://example.com:9821/dbname?ssl=true&application_name=client', {
storage: '/completely/different/path.db',
dialectOptions: {
supportBigNumbers: true,
application_name: 'server',
}
});
const options = sequelize.options;
const dialectOptions = sequelize.config.dialectOptions;
expect(options.storage).to.equal('/completely/different/path.db');
expect(dialectOptions.supportBigNumbers).to.be.true;
expect(dialectOptions.application_name).to.equal('client');
expect(dialectOptions.ssl).to.equal('true');
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!