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 01f8cc37
authored
Oct 18, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first steps for transactions
1 parent
d4d2f7be
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
3 deletions
lib/sequelize.js
lib/transaction.js
lib/utils.js
test/sequelize.test.js
test/transaction.test.js
lib/sequelize.js
View file @
01f8cc3
...
...
@@ -5,6 +5,7 @@ var url = require("url")
,
DataTypes
=
require
(
'./data-types'
)
,
DAOFactoryManager
=
require
(
"./dao-factory-manager"
)
,
QueryInterface
=
require
(
"./query-interface"
)
,
Transaction
=
require
(
"./transaction"
)
module
.
exports
=
(
function
()
{
/**
...
...
@@ -108,7 +109,7 @@ module.exports = (function() {
maxConcurrentQueries
:
this
.
options
.
maxConcurrentQueries
,
dialectOptions
:
this
.
options
.
dialectOptions
,
}
try
{
var
ConnectorManager
=
require
(
"./dialects/"
+
this
.
options
.
dialect
+
"/connector-manager"
)
}
catch
(
err
)
{
...
...
@@ -249,7 +250,7 @@ module.exports = (function() {
// make path relative to the caller
var
callerFilename
=
Utils
.
stack
()[
1
].
getFileName
()
,
callerPath
=
Path
.
dirname
(
callerFilename
)
path
=
Path
.
resolve
(
callerPath
,
path
)
}
...
...
@@ -372,5 +373,12 @@ module.exports = (function() {
return
new
Utils
.
literal
(
val
)
}
Sequelize
.
prototype
.
transaction
=
function
(
_options
,
_callback
)
{
var
options
=
(
typeof
_options
===
'function'
)
?
{}
:
_options
,
callback
=
(
typeof
_options
===
'function'
)
?
_options
:
_callback
callback
(
new
Transaction
(
options
))
}
return
Sequelize
})()
lib/transaction.js
0 → 100644
View file @
01f8cc3
var
Utils
=
require
(
'./utils'
)
var
Transaction
=
module
.
exports
=
function
(
options
)
{
this
.
options
=
options
||
{}
this
.
id
=
Utils
.
generateUUID
()
}
lib/utils.js
View file @
01f8cc3
...
...
@@ -488,7 +488,6 @@ var Utils = module.exports = {
return
stack
;
},
now
:
function
(
dialect
)
{
var
now
=
new
Date
()
if
(
dialect
!=
"postgres"
)
now
.
setMilliseconds
(
0
)
...
...
@@ -524,6 +523,13 @@ var Utils = module.exports = {
},
literal
:
function
(
val
)
{
this
.
val
=
val
},
generateUUID
:
function
()
{
return
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.
replace
(
/
[
xy
]
/g
,
function
(
c
)
{
var
r
=
Math
.
random
()
*
16
|
0
,
v
=
c
==
'x'
?
r
:
(
r
&
0x3
|
0x8
)
return
v
.
toString
(
16
)
})
}
}
...
...
test/sequelize.test.js
View file @
01f8cc3
...
...
@@ -465,5 +465,26 @@ describe(Support.getTestDialectTeaser("Sequelize"), function () {
})
})
describe
(
'transaction'
,
function
()
{
it
(
'is a transaction method available'
,
function
()
{
expect
(
Support
.
Sequelize
).
to
.
respondTo
(
'transaction'
)
})
it
(
'passes a transaction object to the callback'
,
function
(
done
)
{
var
Transaction
=
require
(
__dirname
+
'/../lib/transaction'
)
this
.
sequelize
.
transaction
(
function
(
t
)
{
expect
(
t
).
to
.
be
.
instanceOf
(
Transaction
)
done
()
})
})
it
(
"creates a new connection"
,
function
(
done
)
{
this
.
sequelize
.
transaction
(
function
(
t
)
{
done
()
})
})
})
})
})
test/transaction.test.js
0 → 100644
View file @
01f8cc3
var
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/support'
)
,
Transaction
=
require
(
__dirname
+
'/../lib/transaction'
)
describe
(
Support
.
getTestDialectTeaser
(
"Transaction"
),
function
()
{
describe
(
'constructor'
,
function
()
{
it
(
'stores options'
,
function
()
{
var
transaction
=
new
Transaction
()
expect
(
transaction
.
options
).
to
.
be
.
an
.
instanceOf
(
Object
)
})
it
(
'generates an identifier'
,
function
()
{
var
transaction
=
new
Transaction
()
expect
(
transaction
.
id
).
to
.
exist
})
})
})
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