Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Dialects/mssql.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ exports.escapeVal = function (val, timeZone) {
};

exports.defaultValuesStmt = "DEFAULT VALUES";

exports.limitAsTop = true;
25 changes: 16 additions & 9 deletions lib/Remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ function RemoveQuery(Dialect, opts) {
build: function () {
var query = [], tmp;

query.push("DELETE FROM");
// limit as: SELECT TOP n (MSSQL only)
if (Dialect.limitAsTop && sql.hasOwnProperty("limit")) {
query.push("DELETE TOP " + sql.limit + " FROM");
} else {
query.push("DELETE FROM");
}
query.push(Dialect.escapeId(sql.table));

query = query.concat(Where.build(Dialect, sql.where, opts));
Expand All @@ -46,15 +51,17 @@ function RemoveQuery(Dialect, opts) {
}
}

// limit
if (sql.hasOwnProperty("limit")) {
if (sql.hasOwnProperty("offset")) {
query.push("LIMIT " + sql.limit + " OFFSET " + sql.offset);
} else {
query.push("LIMIT " + sql.limit);
// limit for all Dialects but MSSQL
if (!Dialect.limitAsTop) {
if (sql.hasOwnProperty("limit")) {
if (sql.hasOwnProperty("offset")) {
query.push("LIMIT " + sql.limit + " OFFSET " + sql.offset);
} else {
query.push("LIMIT " + sql.limit);
}
} else if (sql.hasOwnProperty("offset")) {
query.push("OFFSET " + sql.offset);
}
} else if (sql.hasOwnProperty("offset")) {
query.push("OFFSET " + sql.offset);
}

return query.join(" ");
Expand Down
23 changes: 15 additions & 8 deletions lib/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ function SelectQuery(Dialect, opts) {

query.push("SELECT");

// limit as: SELECT TOP n (MSSQL only)
if (Dialect.limitAsTop && sql.hasOwnProperty("limit")) {
query.push("TOP " + sql.limit);
}

for (i = 0; i < sql.from.length; i++) {
sql.from[i].a = "t" + (i + 1);
}
Expand Down Expand Up @@ -399,15 +404,17 @@ function SelectQuery(Dialect, opts) {
}
}

// limit
if (sql.hasOwnProperty("limit")) {
if (sql.hasOwnProperty("offset")) {
query.push("LIMIT " + sql.limit + " OFFSET " + sql.offset);
} else {
query.push("LIMIT " + sql.limit);
// limit for all Dialects but MSSQL
if (!Dialect.limitAsTop) {
if (sql.hasOwnProperty("limit")) {
if (sql.hasOwnProperty("offset")) {
query.push("LIMIT " + sql.limit + " OFFSET " + sql.offset);
} else {
query.push("LIMIT " + sql.limit);
}
} else if (sql.hasOwnProperty("offset")) {
query.push("OFFSET " + sql.offset);
}
} else if (sql.hasOwnProperty("offset")) {
query.push("OFFSET " + sql.offset);
}

return query.join(" ");
Expand Down
6 changes: 6 additions & 0 deletions test/integration/test-dialect-mssql.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ assert.equal(
dialect.defaultValuesStmt,
"DEFAULT VALUES"
);

//Assert that mssql is configured to use the SELECT TOP as a contruct for limit
assert.equal(
dialect.limitAsTop,
true
);
6 changes: 6 additions & 0 deletions test/integration/test-dialect-mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ assert.equal(
dialect.defaultValuesStmt,
"VALUES()"
);

//For all dialects but mssql limitAsTop should be undefined or false
assert.equal(
dialect.limitAsTop || false,
false
);
6 changes: 6 additions & 0 deletions test/integration/test-dialect-postgresql.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ assert.equal(
dialect.defaultValuesStmt,
"DEFAULT VALUES"
);

//For all dialects but mssql limitAsTop should be undefined or false
assert.equal(
dialect.limitAsTop || false,
false
);
6 changes: 6 additions & 0 deletions test/integration/test-dialect-sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,9 @@ assert.equal(
dialect.defaultValuesStmt,
"DEFAULT VALUES"
);

//For all dialects but mssql limitAsTop should be undefined or false
assert.equal(
dialect.limitAsTop || false,
false
);