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 b64b3541
authored
May 29, 2013
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge #527
1 parent
3416639b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
3 deletions
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
lib/dialects/query-generator.js
spec-jasmine/mysql/query-generator.spec.js
spec-jasmine/postgres/query-generator.spec.js
spec-jasmine/sqlite/query-generator.spec.js
lib/dialects/mysql/query-generator.js
View file @
b64b354
...
@@ -290,7 +290,8 @@ module.exports = (function() {
...
@@ -290,7 +290,8 @@ module.exports = (function() {
deleteQuery
:
function
(
tableName
,
where
,
options
)
{
deleteQuery
:
function
(
tableName
,
where
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
var
table
=
QueryGenerator
.
addQuotes
(
tableName
)
var
query
=
options
&&
options
.
truncate
===
true
?
"TRUNCATE "
:
"DELETE FROM "
,
table
=
QueryGenerator
.
addQuotes
(
tableName
)
where
=
QueryGenerator
.
getWhereConditions
(
where
)
where
=
QueryGenerator
.
getWhereConditions
(
where
)
var
limit
=
""
var
limit
=
""
...
@@ -302,7 +303,7 @@ module.exports = (function() {
...
@@ -302,7 +303,7 @@ module.exports = (function() {
limit
=
" LIMIT "
+
Utils
.
escape
(
options
.
limit
)
limit
=
" LIMIT "
+
Utils
.
escape
(
options
.
limit
)
}
}
var
query
=
"DELETE FROM "
+
table
+
" WHERE "
+
where
+
limit
query
+=
table
+
" WHERE "
+
where
+
limit
return
query
return
query
},
},
...
...
lib/dialects/postgres/query-generator.js
View file @
b64b354
...
@@ -369,7 +369,8 @@ module.exports = (function() {
...
@@ -369,7 +369,8 @@ module.exports = (function() {
primaryKeys
[
tableName
]
=
primaryKeys
[
tableName
]
||
[];
primaryKeys
[
tableName
]
=
primaryKeys
[
tableName
]
||
[];
var
query
=
"DELETE FROM <%= table %> WHERE <%= primaryKeys %> IN (SELECT <%= primaryKeysSelection %> FROM <%= table %> WHERE <%= where %><%= limit %>)"
var
query
=
options
&&
options
.
truncate
===
true
?
"TRUNCATE <%= table %>"
:
"DELETE FROM <%= table %>"
query
+=
" WHERE <%= primaryKeys %> IN (SELECT <%= primaryKeysSelection %> FROM <%= table %> WHERE <%= where %><%= limit %>)"
var
pks
;
var
pks
;
if
(
primaryKeys
[
tableName
]
&&
primaryKeys
[
tableName
].
length
>
0
)
{
if
(
primaryKeys
[
tableName
]
&&
primaryKeys
[
tableName
].
length
>
0
)
{
...
...
lib/dialects/query-generator.js
View file @
b64b354
...
@@ -150,6 +150,10 @@ module.exports = (function() {
...
@@ -150,6 +150,10 @@ module.exports = (function() {
If you use a string, you have to escape it on your own.
If you use a string, you have to escape it on your own.
Options:
Options:
- limit -> Maximaum count of lines to delete
- limit -> Maximaum count of lines to delete
- truncate -> boolean - whether to use an 'optimized' mechanism (i.e. TRUNCATE) if available,
note that this should not be the default behaviour because TRUNCATE does not
always play nicely (e.g. InnoDB tables with FK constraints)
(@see http://dev.mysql.com/doc/refman/5.6/en/truncate-table.html)
*/
*/
deleteQuery
:
function
(
tableName
,
where
,
options
)
{
deleteQuery
:
function
(
tableName
,
where
,
options
)
{
throwMethodUndefined
(
'deleteQuery'
)
throwMethodUndefined
(
'deleteQuery'
)
...
...
spec-jasmine/mysql/query-generator.spec.js
View file @
b64b354
...
@@ -300,6 +300,9 @@ describe('QueryGenerator', function() {
...
@@ -300,6 +300,9 @@ describe('QueryGenerator', function() {
},
{
},
{
arguments
:
[
'myTable'
,
1
],
arguments
:
[
'myTable'
,
1
],
expectation
:
"DELETE FROM `myTable` WHERE `id`=1 LIMIT 1"
expectation
:
"DELETE FROM `myTable` WHERE `id`=1 LIMIT 1"
},{
arguments
:
[
'myTable'
,
1
,
{
truncate
:
true
}],
expectation
:
"TRUNCATE `myTable` WHERE `id`=1 LIMIT 1"
},
{
},
{
arguments
:
[
'myTable'
,
1
,
{
limit
:
10
}],
arguments
:
[
'myTable'
,
1
,
{
limit
:
10
}],
expectation
:
"DELETE FROM `myTable` WHERE `id`=1 LIMIT 10"
expectation
:
"DELETE FROM `myTable` WHERE `id`=1 LIMIT 10"
...
...
spec-jasmine/postgres/query-generator.spec.js
View file @
b64b354
...
@@ -293,6 +293,9 @@ describe('QueryGenerator', function() {
...
@@ -293,6 +293,9 @@ describe('QueryGenerator', function() {
arguments
:
[
'myTable'
,
1
],
arguments
:
[
'myTable'
,
1
],
expectation
:
"DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"id\"=1 LIMIT 1)"
expectation
:
"DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"id\"=1 LIMIT 1)"
},
{
},
{
arguments
:
[
'myTable'
,
1
,
{
truncate
:
true
}],
expectation
:
"TRUNCATE \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"id\"=1 LIMIT 1)"
},
{
arguments
:
[
'myTable'
,
1
,
{
limit
:
10
}],
arguments
:
[
'myTable'
,
1
,
{
limit
:
10
}],
expectation
:
"DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"id\"=1 LIMIT 10)"
expectation
:
"DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"id\"=1 LIMIT 10)"
},
{
},
{
...
...
spec-jasmine/sqlite/query-generator.spec.js
View file @
b64b354
...
@@ -199,6 +199,9 @@ describe('QueryGenerator', function() {
...
@@ -199,6 +199,9 @@ describe('QueryGenerator', function() {
arguments
:
[
'myTable'
,
1
],
arguments
:
[
'myTable'
,
1
],
expectation
:
"DELETE FROM `myTable` WHERE `id`=1"
expectation
:
"DELETE FROM `myTable` WHERE `id`=1"
},
{
},
{
arguments
:
[
'myTable'
,
1
,
{
truncate
:
true
}],
expectation
:
"DELETE FROM `myTable` WHERE `id`=1"
},
{
arguments
:
[
'myTable'
,
1
,
{
limit
:
10
}],
arguments
:
[
'myTable'
,
1
,
{
limit
:
10
}],
expectation
:
"DELETE FROM `myTable` WHERE `id`=1"
expectation
:
"DELETE FROM `myTable` WHERE `id`=1"
},
{
},
{
...
...
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