不要怂,就是干,撸起袖子干!

Commit 182caa98 by Jan Aagaard Meier

Closes #723

1 parent 3c14f562
...@@ -217,8 +217,14 @@ module.exports = (function() { ...@@ -217,8 +217,14 @@ module.exports = (function() {
query += " ORDER BY " + options.order query += " ORDER BY " + options.order
} }
if (options.offset && !options.limit) {
if (options.limit && !(options.include && (options.limit === 1))) { /*
* If not limit is defined, our best bet is to use the max number of rows in a table. From the MySQL docs:
* There is a limit of 2^32 (~4.295E+09) rows in a MyISAM table. If you build MySQL with the --with-big-tables option,
* the row limitation is increased to (2^32)^2 (1.844E+19) rows.
*/
query += " LIMIT " + options.offset + ", " + 18440000000000000000;
} else if (options.limit && !(options.include && (options.limit === 1))) {
if (options.offset) { if (options.offset) {
query += " LIMIT " + options.offset + ", " + options.limit query += " LIMIT " + options.offset + ", " + options.limit
} else { } else {
......
...@@ -188,8 +188,13 @@ module.exports = (function() { ...@@ -188,8 +188,13 @@ module.exports = (function() {
query += " ORDER BY " + options.order query += " ORDER BY " + options.order
} }
if (options.offset && !options.limit) {
if (options.limit && !(options.include && (options.limit === 1))) { /*
* If not limit is defined, our best bet is to use the max number of rows in a table. From the SQLite docs:
* A 140 terabytes database can hold no more than approximately 1e+13 rows
*/
query += " LIMIT " + options.offset + ", " + 10000000000000;
} else if (options.limit && !(options.include && (options.limit === 1))) {
if (options.offset) { if (options.offset) {
query += " LIMIT " + options.offset + ", " + options.limit query += " LIMIT " + options.offset + ", " + options.limit
} else { } else {
......
...@@ -238,9 +238,7 @@ describe('DAOFactory', function() { ...@@ -238,9 +238,7 @@ describe('DAOFactory', function() {
}) })
}) })
}) })
/*
// at time of writing (v1.6.0) Sequelize does not seem to support 'offset' on it's own consistently (goes wrong for PostGRES and SQLite)
it("handles offset", function() { it("handles offset", function() {
Helpers.async(function(done) { Helpers.async(function(done) {
User.findAndCountAll({offset: 1}).success(function(info) { User.findAndCountAll({offset: 1}).success(function(info) {
...@@ -251,7 +249,7 @@ describe('DAOFactory', function() { ...@@ -251,7 +249,7 @@ describe('DAOFactory', function() {
}) })
}) })
}) })
*/
it("handles limit", function() { it("handles limit", function() {
Helpers.async(function(done) { Helpers.async(function(done) {
User.findAndCountAll({limit: 1}).success(function(info) { User.findAndCountAll({limit: 1}).success(function(info) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!