Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow options to be a JSON object #12404

Merged
merged 8 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/sequelize.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,19 @@ class Sequelize {

if (options.dialectOptions)
Object.assign(options.dialectOptions, urlParts.query);
else
else
{
yorek marked this conversation as resolved.
Show resolved Hide resolved
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 {
// new Sequelize(database, username, password, { ... options })
Expand Down
8 changes: 8 additions & 0 deletions test/integration/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ describe(Support.getTestDialectTeaser('Configuration'), () => {
});
});

describe('Instantiation with a URL string', () => {
yorek marked this conversation as resolved.
Show resolved Hide resolved
it('should handle options in URL', () => {
const sequelizeWithOptions = new Sequelize('mssql://user:password!@server.database.windows.net/database?options={"encrypt":true}&anotherOption=1');
expect(sequelizeWithOptions.options.dialectOptions.options.encrypt).to.equal(true);
expect(sequelizeWithOptions.options.dialectOptions.anotherOption).to.equal('1');
});
});

describe('Instantiation with arguments', () => {
if (dialect === 'sqlite') {
it('should respect READONLY / READWRITE connection modes', async () => {
Expand Down