From 70e3c942fdb7a08eea8d42026e4089aefe42f50f Mon Sep 17 00:00:00 2001 From: dfahlander Date: Wed, 30 May 2018 11:53:32 +0200 Subject: [PATCH 1/2] Order results correctly when using getAll() and getAllKeys() This will hopefully resolve the ordering issue listed in https://github.com/dfahlander/Dexie.js/issues/709 https://github.com/dfahlander/Dexie.js/issues/701 --- src/IDBIndex.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/IDBIndex.js b/src/IDBIndex.js index 1fde55f1..c22d3029 100644 --- a/src/IDBIndex.js +++ b/src/IDBIndex.js @@ -651,6 +651,9 @@ function buildFetchIndexDataSQL (nullDisallowed, index, range, opType, multiChec setSQLForKeyRange(convertedRange, util.escapeIndexNameForSQL(index.name), sql, sqlValues, true, false); } } + if (opType !== 'count') { + sql.push('ORDER BY ', util.escapeIndexNameForSQL(index.name)); + } return [nullDisallowed, index, hasRange, range, opType, multiChecks, sql, sqlValues]; } From 34330490b2de14a1388ea75b7445dd31187a7bb8 Mon Sep 17 00:00:00 2001 From: dfahlander Date: Thu, 31 May 2018 11:57:18 +0200 Subject: [PATCH 2/2] Correction: Should order by index + primary key - not just index. This fix made 2 other assertions in dexie unit tests turn from fail to ok. --- src/IDBIndex.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IDBIndex.js b/src/IDBIndex.js index c22d3029..9ad99b5b 100644 --- a/src/IDBIndex.js +++ b/src/IDBIndex.js @@ -652,7 +652,7 @@ function buildFetchIndexDataSQL (nullDisallowed, index, range, opType, multiChec } } if (opType !== 'count') { - sql.push('ORDER BY ', util.escapeIndexNameForSQL(index.name)); + sql.push('ORDER BY', util.escapeIndexNameForSQL(index.name), ',', util.sqlQuote('key')); } return [nullDisallowed, index, hasRange, range, opType, multiChecks, sql, sqlValues]; }