Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 663261bf
authored
Jun 23, 2020
by
Davide Mauri
Committed by
GitHub
Jun 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(sequelize): allow passing dialectOptions.options from url (#12404)
1 parent
c6e41928
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
lib/sequelize.js
test/unit/configuration.test.js
lib/sequelize.js
View file @
663261b
...
@@ -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 })
...
...
test/unit/configuration.test.js
View file @
663261b
...
@@ -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'
);
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment