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 9cd22912
authored
Oct 14, 2014
by
Bryan Tong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/sequelize/sequelize
2 parents
7d2c7de4
c63ccaf6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
16 deletions
lib/dialects/abstract/query-generator.js
lib/dialects/postgres/query.js
lib/query-interface.js
lib/transaction.js
lib/dialects/abstract/query-generator.js
View file @
9cd2291
...
@@ -1130,10 +1130,15 @@ module.exports = (function() {
...
@@ -1130,10 +1130,15 @@ module.exports = (function() {
/**
/**
* Returns a query that starts a transaction.
* Returns a query that starts a transaction.
*
*
* @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @param {Boolean} value A boolean that states whether autocommit shall be done or not.
* @return {String} The generated sql query.
* @param {Object} options An object with options.
* @return {String} The generated sql query.
*/
*/
setAutocommitQuery
:
function
(
value
)
{
setAutocommitQuery
:
function
(
value
,
options
)
{
if
(
options
.
parent
)
{
return
;
}
return
'SET autocommit = '
+
(
!!
value
?
1
:
0
)
+
';'
;
return
'SET autocommit = '
+
(
!!
value
?
1
:
0
)
+
';'
;
},
},
...
...
lib/dialects/postgres/query.js
View file @
9cd2291
...
@@ -256,15 +256,24 @@ module.exports = (function() {
...
@@ -256,15 +256,24 @@ module.exports = (function() {
parent
:
err
parent
:
err
});
});
case
'23505'
:
case
'23505'
:
match
=
err
.
detail
.
match
(
/Key
\((
.*
?)\)
=
\((
.*
?)\)
already exists/
);
// there are multiple different formats of error messages for this error code
// this regex should check at least two
return
new
sequelizeErrors
.
UniqueConstraintError
({
match
=
err
.
detail
.
match
(
/Key
\((
.*
?)\)
=
\((
.*
?)\)
/
);
fields
:
match
[
1
].
split
(
', '
),
value
:
match
[
2
].
split
(
', '
),
if
(
match
)
{
index
:
null
,
return
new
sequelizeErrors
.
UniqueConstraintError
({
parent
:
err
fields
:
match
[
1
].
split
(
', '
),
});
value
:
match
[
2
].
split
(
', '
),
index
:
null
,
parent
:
err
});
}
else
{
return
new
sequelizeErrors
.
UniqueConstraintError
({
error
:
err
,
message
:
err
.
message
});
}
break
;
default
:
default
:
return
new
sequelizeErrors
.
DatabaseError
(
err
);
return
new
sequelizeErrors
.
DatabaseError
(
err
);
}
}
...
...
lib/query-interface.js
View file @
9cd2291
...
@@ -712,13 +712,21 @@ module.exports = (function() {
...
@@ -712,13 +712,21 @@ module.exports = (function() {
return
this
.
QueryGenerator
.
escape
(
value
);
return
this
.
QueryGenerator
.
escape
(
value
);
};
};
QueryInterface
.
prototype
.
setAutocommit
=
function
(
transaction
,
value
)
{
QueryInterface
.
prototype
.
setAutocommit
=
function
(
transaction
,
value
,
options
)
{
if
(
!
transaction
||
!
(
transaction
instanceof
Transaction
))
{
if
(
!
transaction
||
!
(
transaction
instanceof
Transaction
))
{
throw
new
Error
(
'Unable to set autocommit for a transaction without transaction object!'
);
throw
new
Error
(
'Unable to set autocommit for a transaction without transaction object!'
);
}
}
var
sql
=
this
.
QueryGenerator
.
setAutocommitQuery
(
value
);
options
=
Utils
.
_
.
extend
({
return
this
.
sequelize
.
query
(
sql
,
null
,
{
transaction
:
transaction
});
parent
:
options
.
transaction
},
options
||
{});
var
sql
=
this
.
QueryGenerator
.
setAutocommitQuery
(
value
,
options
);
if
(
sql
)
{
return
this
.
sequelize
.
query
(
sql
,
null
,
{
transaction
:
transaction
});
}
else
{
return
Utils
.
Promise
.
resolve
();
}
};
};
QueryInterface
.
prototype
.
setIsolationLevel
=
function
(
transaction
,
value
,
options
)
{
QueryInterface
.
prototype
.
setIsolationLevel
=
function
(
transaction
,
value
,
options
)
{
...
...
lib/transaction.js
View file @
9cd2291
...
@@ -136,7 +136,7 @@ Transaction.prototype.setAutocommit = function() {
...
@@ -136,7 +136,7 @@ Transaction.prototype.setAutocommit = function() {
return
this
return
this
.
sequelize
.
sequelize
.
getQueryInterface
()
.
getQueryInterface
()
.
setAutocommit
(
this
,
this
.
options
.
autocommit
);
.
setAutocommit
(
this
,
this
.
options
.
autocommit
,
this
.
options
);
};
};
Transaction
.
prototype
.
setIsolationLevel
=
function
()
{
Transaction
.
prototype
.
setIsolationLevel
=
function
()
{
...
...
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