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 02bceaa3
authored
Dec 20, 2016
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: afterConnect hook
1 parent
4f95f176
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
5 deletions
changelog.md
lib/dialects/abstract/connection-manager.js
lib/hooks.js
test/unit/connection-manager.test.js
changelog.md
View file @
02bceaa
# Future
# Future
-
[
FIXED
]
Soft-delete not returning number of affected rows on mssql
[
#6916
](
https://github.com/sequelize/sequelize/pull/6916
)
-
[
FIXED
]
Soft-delete not returning number of affected rows on mssql
[
#6916
](
https://github.com/sequelize/sequelize/pull/6916
)
-
[
ADDED
]
`afterConnect`
hook
# 3.27.0
# 3.27.0
-
[
FIXED
]
Incorrect column name for generateThroughJoin
[
#6878
](
https://github.com/sequelize/sequelize/pull/6878
)
-
[
FIXED
]
Incorrect column name for generateThroughJoin
[
#6878
](
https://github.com/sequelize/sequelize/pull/6878
)
...
...
lib/dialects/abstract/connection-manager.js
View file @
02bceaa
...
@@ -244,9 +244,9 @@ ConnectionManager.prototype.releaseConnection = function(connection) {
...
@@ -244,9 +244,9 @@ ConnectionManager.prototype.releaseConnection = function(connection) {
ConnectionManager
.
prototype
.
$connect
=
function
(
config
)
{
ConnectionManager
.
prototype
.
$connect
=
function
(
config
)
{
return
this
.
sequelize
.
runHooks
(
'beforeConnect'
,
config
).
bind
(
this
).
then
(
function
()
{
return
this
.
sequelize
.
runHooks
(
'beforeConnect'
,
config
).
bind
(
this
).
then
(
function
()
{
return
this
.
dialect
.
connectionManager
.
connect
(
config
)
.
then
(
function
(
connection
)
{
return
this
.
dialect
.
connectionManager
.
connect
(
config
)
;
return
connection
;
}).
then
(
function
(
connection
)
{
});
return
this
.
sequelize
.
runHooks
(
'afterConnect'
,
connection
,
config
).
return
(
connection
)
});
});
};
};
ConnectionManager
.
prototype
.
$disconnect
=
function
(
connection
)
{
ConnectionManager
.
prototype
.
$disconnect
=
function
(
connection
)
{
...
@@ -254,7 +254,7 @@ ConnectionManager.prototype.$disconnect = function(connection) {
...
@@ -254,7 +254,7 @@ ConnectionManager.prototype.$disconnect = function(connection) {
};
};
ConnectionManager
.
prototype
.
$validate
=
function
(
connection
)
{
ConnectionManager
.
prototype
.
$validate
=
function
(
connection
)
{
if
(
!
this
.
dialect
.
connectionManager
.
validate
)
return
Promise
.
resolve
();
if
(
!
this
.
dialect
.
connectionManager
.
validate
)
return
true
return
this
.
dialect
.
connectionManager
.
validate
(
connection
);
return
this
.
dialect
.
connectionManager
.
validate
(
connection
);
};
};
...
...
lib/hooks.js
View file @
02bceaa
...
@@ -66,6 +66,7 @@ var hookTypes = {
...
@@ -66,6 +66,7 @@ var hookTypes = {
beforeInit
:
{
params
:
2
,
sync
:
true
},
beforeInit
:
{
params
:
2
,
sync
:
true
},
afterInit
:
{
params
:
1
,
sync
:
true
},
afterInit
:
{
params
:
1
,
sync
:
true
},
beforeConnect
:
{
params
:
1
},
beforeConnect
:
{
params
:
1
},
afterConnect
:
{
params
:
2
},
beforeSync
:
{
params
:
1
},
beforeSync
:
{
params
:
1
},
afterSync
:
{
params
:
1
},
afterSync
:
{
params
:
1
},
beforeBulkSync
:
{
params
:
1
},
beforeBulkSync
:
{
params
:
1
},
...
@@ -420,6 +421,31 @@ Hooks.hasHooks = Hooks.hasHook;
...
@@ -420,6 +421,31 @@ Hooks.hasHooks = Hooks.hasHook;
* @param {String} name
* @param {String} name
* @param {Function} fn A callback function that is called with sequelize
* @param {Function} fn A callback function that is called with sequelize
* @name afterInit
* @name afterInit
* @memberOf Sequelize
*/
/**
* A hook that is run before a connection is created
* @param {String} name
* @param {Function} fn A callback function that is called with config passed to connection
* @name beforeConnect
* @memberOf Sequelize
*/
/**
* A hook that is run after a connection is created
* @param {String} name
* @param {Function} fn A callback function that is called with the connection object and thye config passed to connection
* @name afterConnect
* @memberOf Sequelize
*/
/**
* A hook that is run before Model.sync call
* @param {String} name
* @param {Function} fn A callback function that is called with options passed to Model.sync
* @name beforeSync
* @memberOf Sequelize
*/
*/
/**
/**
...
...
test/unit/connection-manager.test.js
View file @
02bceaa
...
@@ -13,10 +13,11 @@ describe('connection manager', function () {
...
@@ -13,10 +13,11 @@ describe('connection manager', function () {
describe
(
'$connect'
,
function
()
{
describe
(
'$connect'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
this
.
sinon
=
sinon
.
sandbox
.
create
();
this
.
sinon
=
sinon
.
sandbox
.
create
();
this
.
connection
=
{};
this
.
dialect
=
{
this
.
dialect
=
{
connectionManager
:
{
connectionManager
:
{
connect
:
this
.
sinon
.
stub
().
returns
(
Promise
.
resolve
())
connect
:
this
.
sinon
.
stub
().
returns
(
Promise
.
resolve
(
this
.
connection
))
}
}
};
};
...
@@ -59,5 +60,18 @@ describe('connection manager', function () {
...
@@ -59,5 +60,18 @@ describe('connection manager', function () {
});
});
}.
bind
(
this
));
}.
bind
(
this
));
});
});
it
(
'should call afterConnect'
,
function
()
{
const
spy
=
sinon
.
spy
();
this
.
sequelize
.
afterConnect
(
spy
);
var
connectionManager
=
new
ConnectionManager
(
this
.
dialect
,
this
.
sequelize
);
return
connectionManager
.
$connect
({}).
then
(()
=>
{
expect
(
spy
.
callCount
).
to
.
equal
(
1
);
expect
(
spy
.
firstCall
.
args
[
0
]).
to
.
equal
(
this
.
connection
);
expect
(
spy
.
firstCall
.
args
[
1
]).
to
.
eql
({});
});
});
});
});
});
});
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