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 3a6352d9
authored
Oct 20, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
let the transaction set the initial transaction state
1 parent
84c89570
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
22 deletions
lib/dialects/abstract/query-generator.js
lib/dialects/mysql/query-generator.js
lib/query-interface.js
lib/sequelize.js
lib/transaction.js
lib/dialects/abstract/query-generator.js
View file @
3a6352d
...
...
@@ -464,6 +464,10 @@ module.exports = (function() {
throwMethodUndefined
(
'setAutocommitQuery'
)
},
setIsolationLevelQuery
:
function
(
value
)
{
throwMethodUndefined
(
'setIsolationLevelQuery'
)
},
/**
* Returns a query that starts a transaction.
*
...
...
lib/dialects/mysql/query-generator.js
View file @
3a6352d
...
...
@@ -337,6 +337,10 @@ module.exports = (function() {
return
"SET autocommit = "
+
(
!!
value
?
1
:
0
)
+
";"
},
setIsolationLevelQuery
:
function
(
value
)
{
return
"SET SESSION TRANSACTION ISOLATION LEVEL "
+
value
+
";"
},
/**
* Returns a query that starts a transaction.
*
...
...
lib/query-interface.js
View file @
3a6352d
...
...
@@ -808,6 +808,15 @@ module.exports = (function() {
return
this
.
queryAndEmit
([
sql
,
null
,
{
transaction
:
transaction
}],
'setAutocommit'
)
}
QueryInterface
.
prototype
.
setIsolationLevel
=
function
(
transaction
,
value
)
{
if
(
!
transaction
||
!
(
transaction
instanceof
Transaction
))
{
throw
new
Error
(
'Unable to set isolatipn level for a transaction without transaction object!'
)
}
var
sql
=
this
.
QueryGenerator
.
setIsolationLevelQuery
(
value
)
return
this
.
queryAndEmit
([
sql
,
null
,
{
transaction
:
transaction
}],
'setIsolationLevel'
)
}
QueryInterface
.
prototype
.
startTransaction
=
function
(
transaction
,
options
)
{
if
(
!
transaction
||
!
(
transaction
instanceof
Transaction
))
{
throw
new
Error
(
'Unable to start a transaction without transaction object!'
)
...
...
lib/sequelize.js
View file @
3a6352d
...
...
@@ -393,28 +393,15 @@ module.exports = (function() {
,
transaction
=
new
Transaction
(
this
,
options
)
,
self
=
this
var
startTransaction
=
function
()
{
self
.
getQueryInterface
()
.
startTransaction
(
transaction
,
{})
.
success
(
function
()
{
callback
(
transaction
)
})
}
var
setAutocommit
=
function
(
value
,
cb
)
{
self
.
getQueryInterface
()
.
setAutocommit
(
transaction
,
value
)
.
success
(
cb
)
}
Utils
.
tick
(
function
()
{
if
(
options
.
hasOwnProperty
(
'autocommit'
))
{
setAutocommit
(
!!
options
.
autocommit
,
startTransaction
)
}
else
{
startTransaction
()
}
transaction
.
prepareEnvironment
(
function
()
{
self
.
getQueryInterface
()
.
startTransaction
(
transaction
,
{})
.
success
(
function
()
{
callback
(
transaction
)
})
})
})
return
transaction
...
...
lib/transaction.js
View file @
3a6352d
...
...
@@ -3,12 +3,22 @@ var Utils = require('./utils')
var
Transaction
=
module
.
exports
=
function
(
sequelize
,
options
)
{
this
.
sequelize
=
sequelize
this
.
options
=
options
||
{}
this
.
id
=
Utils
.
generateUUID
()
this
.
options
=
Utils
.
_
.
extend
({
autocommit
:
true
,
isolationLevel
:
Transaction
.
ISOLATION_LEVELS
.
REPEATABLE_READ
},
options
||
{})
}
util
.
inherits
(
Transaction
,
Utils
.
CustomEventEmitter
)
Transaction
.
ISOLATION_LEVELS
=
{
READ_UNCOMMITTED
:
"READ UNCOMMITTED"
,
READ_COMMITTED
:
"READ COMMITTED"
,
REPEATABLE_READ
:
"REPEATABLE READ"
,
SERIALIZABLE
:
"SERIALIZABLE"
}
Transaction
.
prototype
.
commit
=
function
()
{
return
this
.
sequelize
...
...
@@ -25,3 +35,29 @@ Transaction.prototype.rollback = function() {
.
rollbackTransaction
(
this
,
{})
.
proxy
(
this
)
}
Transaction
.
prototype
.
prepareEnvironment
=
function
(
callback
)
{
var
self
=
this
this
.
setIsolationLevel
(
function
()
{
self
.
setAutocommit
(
function
()
{
callback
()
})
})
}
Transaction
.
prototype
.
setAutocommit
=
function
(
callback
)
{
this
.
sequelize
.
getQueryInterface
()
.
setAutocommit
(
this
,
this
.
options
.
autocommit
)
.
success
(
callback
)
}
Transaction
.
prototype
.
setIsolationLevel
=
function
(
callback
)
{
this
.
sequelize
.
getQueryInterface
()
.
setIsolationLevel
(
this
,
this
.
options
.
isolationLevel
)
.
success
(
callback
)
}
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