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 303b453a
authored
Apr 23, 2020
by
Andy Edwards
Committed by
GitHub
Apr 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(transaction): asyncify methods (#12156)
1 parent
80de9f60
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
42 deletions
lib/transaction.js
lib/transaction.js
View file @
303b453
...
@@ -64,7 +64,7 @@ class Transaction {
...
@@ -64,7 +64,7 @@ class Transaction {
}
finally
{
}
finally
{
this
.
finished
=
'commit'
;
this
.
finished
=
'commit'
;
if
(
!
this
.
parent
)
{
if
(
!
this
.
parent
)
{
await
this
.
cleanup
();
this
.
cleanup
();
}
}
for
(
const
hook
of
this
.
_afterCommitHooks
)
{
for
(
const
hook
of
this
.
_afterCommitHooks
)
{
await
hook
.
apply
(
this
,
[
this
]);
await
hook
.
apply
(
this
,
[
this
]);
...
@@ -77,30 +77,30 @@ class Transaction {
...
@@ -77,30 +77,30 @@ class Transaction {
*
*
* @returns {Promise}
* @returns {Promise}
*/
*/
rollback
()
{
async
rollback
()
{
if
(
this
.
finished
)
{
if
(
this
.
finished
)
{
return
Promise
.
reject
(
new
Error
(
`Transaction cannot be rolled back because it has been finished with state:
${
this
.
finished
}
`
)
);
throw
new
Error
(
`Transaction cannot be rolled back because it has been finished with state:
${
this
.
finished
}
`
);
}
}
if
(
!
this
.
connection
)
{
if
(
!
this
.
connection
)
{
return
Promise
.
reject
(
new
Error
(
'Transaction cannot be rolled back because it never started'
)
);
throw
new
Error
(
'Transaction cannot be rolled back because it never started'
);
}
}
this
.
_clearCls
();
this
.
_clearCls
();
return
this
try
{
.
sequelize
return
await
this
.
getQueryInterface
()
.
sequelize
.
rollbackTransaction
(
this
,
this
.
options
)
.
getQueryInterface
(
)
.
finally
(()
=>
{
.
rollbackTransaction
(
this
,
this
.
options
);
if
(
!
this
.
parent
)
{
}
finally
{
return
this
.
cleanup
();
if
(
!
this
.
parent
)
{
}
this
.
cleanup
();
return
this
;
}
});
}
}
}
prepareEnvironment
(
useCLS
)
{
async
prepareEnvironment
(
useCLS
)
{
let
connectionPromise
;
let
connectionPromise
;
if
(
useCLS
===
undefined
)
{
if
(
useCLS
===
undefined
)
{
...
@@ -117,47 +117,49 @@ class Transaction {
...
@@ -117,47 +117,49 @@ class Transaction {
connectionPromise
=
this
.
sequelize
.
connectionManager
.
getConnection
(
acquireOptions
);
connectionPromise
=
this
.
sequelize
.
connectionManager
.
getConnection
(
acquireOptions
);
}
}
return
connectionPromise
let
result
;
.
then
(
connection
=>
{
const
connection
=
await
connectionPromise
;
this
.
connection
=
connection
;
this
.
connection
=
connection
;
this
.
connection
.
uuid
=
this
.
id
;
this
.
connection
.
uuid
=
this
.
id
;
})
.
then
(()
=>
{
try
{
return
this
.
begin
()
await
this
.
begin
();
.
then
(()
=>
this
.
setDeferrable
())
result
=
await
this
.
setDeferrable
();
.
catch
(
setupErr
=>
this
.
rollback
().
finally
(()
=>
{
}
catch
(
setupErr
)
{
throw
setupErr
;
try
{
}));
result
=
await
this
.
rollback
();
})
}
finally
{
.
then
(
result
=>
{
throw
setupErr
;
// eslint-disable-line no-unsafe-finally
if
(
useCLS
&&
this
.
sequelize
.
constructor
.
_cls
)
{
}
this
.
sequelize
.
constructor
.
_cls
.
set
(
'transaction'
,
this
);
}
}
return
Promise
.
resolve
(
null
).
then
(()
=>
result
);
if
(
useCLS
&&
this
.
sequelize
.
constructor
.
_cls
)
{
});
this
.
sequelize
.
constructor
.
_cls
.
set
(
'transaction'
,
this
);
}
return
result
;
}
}
setDeferrable
()
{
async
setDeferrable
()
{
if
(
this
.
options
.
deferrable
)
{
if
(
this
.
options
.
deferrable
)
{
return
this
return
await
this
.
sequelize
.
sequelize
.
getQueryInterface
()
.
getQueryInterface
()
.
deferConstraints
(
this
,
this
.
options
);
.
deferConstraints
(
this
,
this
.
options
);
}
}
}
}
begin
()
{
async
begin
()
{
const
queryInterface
=
this
.
sequelize
.
getQueryInterface
();
const
queryInterface
=
this
.
sequelize
.
getQueryInterface
();
if
(
this
.
sequelize
.
dialect
.
supports
.
settingIsolationLevelDuringTransaction
)
{
if
(
this
.
sequelize
.
dialect
.
supports
.
settingIsolationLevelDuringTransaction
)
{
return
queryInterface
.
startTransaction
(
this
,
this
.
options
).
then
(()
=>
{
await
queryInterface
.
startTransaction
(
this
,
this
.
options
);
return
queryInterface
.
setIsolationLevel
(
this
,
this
.
options
.
isolationLevel
,
this
.
options
);
return
queryInterface
.
setIsolationLevel
(
this
,
this
.
options
.
isolationLevel
,
this
.
options
);
});
}
}
return
queryInterface
.
setIsolationLevel
(
this
,
this
.
options
.
isolationLevel
,
this
.
options
).
then
(()
=>
{
await
queryInterface
.
setIsolationLevel
(
this
,
this
.
options
.
isolationLevel
,
this
.
options
);
return
queryInterface
.
startTransaction
(
this
,
this
.
options
);
}
);
return
queryInterface
.
startTransaction
(
this
,
this
.
options
);
}
}
cleanup
()
{
cleanup
()
{
...
...
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