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

Commit 663261bf by Davide Mauri Committed by GitHub

feat(sequelize): allow passing dialectOptions.options from url (#12404)

1 parent c6e41928
...@@ -217,10 +217,20 @@ class Sequelize { ...@@ -217,10 +217,20 @@ class Sequelize {
options.host = urlParts.query.host; options.host = urlParts.query.host;
} }
if (options.dialectOptions) if (options.dialectOptions) {
Object.assign(options.dialectOptions, urlParts.query); Object.assign(options.dialectOptions, urlParts.query);
else } else {
options.dialectOptions = urlParts.query; options.dialectOptions = urlParts.query;
if (urlParts.query.options) {
try {
const o = JSON.parse(urlParts.query.options);
options.dialectOptions.options = o;
} catch (e) {
// Nothing to do, string is not a valid JSON
// an thus does not need any further processing
}
}
}
} }
} else { } else {
// new Sequelize(database, username, password, { ... options }) // new Sequelize(database, username, password, { ... options })
......
...@@ -180,6 +180,12 @@ describe('Sequelize', () => { ...@@ -180,6 +180,12 @@ describe('Sequelize', () => {
expect(dialectOptions.ssl).to.equal('true'); expect(dialectOptions.ssl).to.equal('true');
}); });
it('should handle JSON options', () => {
const sequelizeWithOptions = new Sequelize('mysql://example.com:9821/dbname?options={"encrypt":true}&anotherOption=1');
expect(sequelizeWithOptions.options.dialectOptions.options.encrypt).to.be.true;
expect(sequelizeWithOptions.options.dialectOptions.anotherOption).to.equal('1');
});
it('should use query string host if specified', () => { it('should use query string host if specified', () => {
const sequelize = new Sequelize('mysql://localhost:9821/dbname?host=example.com'); const sequelize = new Sequelize('mysql://localhost:9821/dbname?host=example.com');
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!