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 2bb1845c
authored
Jul 23, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a close method to sequelize to close the pool and unbind the process.exit handler. Closes #2020
1 parent
32594fea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
lib/dialects/abstract/connection-manager.js
lib/sequelize.js
lib/dialects/abstract/connection-manager.js
View file @
2bb1845
...
@@ -39,13 +39,22 @@ ConnectionManager = function(dialect, sequelize) {
...
@@ -39,13 +39,22 @@ ConnectionManager = function(dialect, sequelize) {
if
(
config
.
pool
.
maxConnections
)
config
.
pool
.
max
=
config
.
pool
.
maxConnections
;
if
(
config
.
pool
.
maxConnections
)
config
.
pool
.
max
=
config
.
pool
.
maxConnections
;
if
(
config
.
pool
.
minConnections
)
config
.
pool
.
min
=
config
.
pool
.
minConnections
;
if
(
config
.
pool
.
minConnections
)
config
.
pool
.
min
=
config
.
pool
.
minConnections
;
this
.
onProcessExit
=
function
()
{
process
.
on
(
'exit'
,
this
.
onProcessExit
.
bind
(
this
));
// Cleanup
};
self
.
pool
.
drain
();
return
;
ConnectionManager
.
prototype
.
onProcessExit
=
function
()
{
}.
bind
(
this
);
if
(
this
.
pool
)
{
this
.
pool
.
drain
();
}
};
ConnectionManager
.
prototype
.
close
=
function
()
{
this
.
onProcessExit
();
process
.
removeListener
(
'exit'
,
this
.
onProcessExit
);
// Remove the listener, so all references to this instance can be garbage collected.
process
.
on
(
'exit'
,
this
.
onProcessExit
);
this
.
getConnection
=
function
()
{
return
Promise
.
reject
(
new
Error
(
"ConnectionManager.getConnection was called after the connection manager was closed!"
));
};
};
};
// This cannot happen in the constructor because the user can specify a min. number of connections to have in the pool
// This cannot happen in the constructor because the user can specify a min. number of connections to have in the pool
...
...
lib/sequelize.js
View file @
2bb1845
...
@@ -802,5 +802,15 @@ module.exports = (function() {
...
@@ -802,5 +802,15 @@ module.exports = (function() {
}
}
};
};
/**
* Close all connections used by this sequelize instance, and free all references so the instance can be garbage collected.
*
* Normally this is done on process exit, so you only need to call this method if you are creating multiple instances, and want
* to garbage collect some of them.
*/
Sequelize
.
prototype
.
close
=
function
()
{
this
.
connectionManager
.
close
();
};
return
Sequelize
;
return
Sequelize
;
})();
})();
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