Permalink
Browse files

Add support for non-indexed columns to better interoperate with WebSQL

  • Loading branch information...
1 parent cf1eec3 commit 508c215ed4286ad03b86cc1500f90994f69b00e6 @kriszyp kriszyp committed Feb 21, 2014
Showing with 15 additions and 9 deletions.
  1. +3 −2 store/db/IndexedDB.js
  2. +4 −1 store/db/SQL.js
  3. +8 −6 store/tests/LocalStorage.js
View
5 store/db/IndexedDB.js
@@ -155,7 +155,8 @@ define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/Deferred', 'dojo/when', '
idbStore = openRequest.transaction.objectStore(storeName);
}
for (var index in storeConfig) {
- if (!idbStore.indexNames.contains(index) && index !== 'autoIncrement') {
+ if (!idbStore.indexNames.contains(index) && index !== 'autoIncrement' &&
+ storeConfig[index].indexed !== false) {
idbStore.createIndex(index, index, storeConfig[index]);
}
}
@@ -434,7 +435,7 @@ define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/Deferred', 'dojo/when', '
function tryIndex(indexName, quality, factor) {
indexTries++;
var indexDefinition = store.indices[indexName];
- if (indexDefinition) {
+ if (indexDefinition && indexDefinition.indexed !== false) {
quality = quality || indexDefinition.preference * (factor || 1) || 0.001;
if (quality > bestIndexQuality) {
bestIndexQuality = quality;
View
5 store/db/SQL.js
@@ -59,7 +59,10 @@ define(['dojo/_base/declare', 'dojo/Deferred', 'dojo/when', 'dojo/store/util/Que
/* suppress failed alter table statements*/
}));
// otherwise, a basic index will do
- promises.push(this.executeSql("CREATE INDEX IF NOT EXISTS " + indexPrefix + table + '_' + index + ' ON ' + table + '(' + index + ')'));
+ if(storeConfig[index].indexed !== false){
+ promises.push(this.executeSql("CREATE INDEX IF NOT EXISTS " + indexPrefix +
+ table + '_' + index + ' ON ' + table + '(' + index + ')'));
+ }
}
}
}
View
14 store/tests/LocalStorage.js
@@ -6,14 +6,14 @@ define([
'dojo/promise/all'
], function (registerSuite, assert, IndexedDB, SQL, all) {
var data = [
- {id: 1, name: 'one', prime: false, mappedTo: 'E', words: ['bananna']},
- {id: 2, name: 'two', even: true, prime: true, mappedTo: 'D', words: ['bananna', 'orange']},
+ {id: 1, name: 'one', prime: false, mappedTo: 'E', words: ['banana']},
+ {id: 2, name: 'two', even: true, prime: true, mappedTo: 'D', words: ['banana', 'orange']},
{id: 3, name: 'three', prime: true, mappedTo: 'C', words: ['apple', 'orange']},
{id: 4, name: 'four', even: true, prime: false, mappedTo: null},
{id: 5, name: 'five', prime: true, mappedTo: 'A'}
];
var dbConfig = {
- version: 4,
+ version: 5,
stores: {
test: {
name: 10,
@@ -39,6 +39,8 @@ define([
registerSuite(testsForDB('dojox/store/db/SQL', SQL));
}
function testsForDB(name, DB){
+ // need to reset availability
+ dbConfig.available = null;
var db = new DB({dbConfig: dbConfig, storeName: 'test'});
function testQuery(query, options, results){
if(!results){
@@ -94,9 +96,9 @@ define([
"{name: 'not a number'}": testQuery({name: 'not a number'}, []),
"{words: {contains: ['orange']}}": testQuery({words: {contains: ['orange']}}, [2, 3]),
"{words: {contains: ['or*']}}": testQuery({words: {contains: ['or*']}}, [2, 3]),
- "{words: {contains: ['apple', 'bananna']}}": testQuery({words: {contains: ['apple', 'bananna']}}, []),
- "{words: {contains: ['orange', 'bananna']}}": testQuery({words: {contains: ['orange', 'bananna']}}, [2]),
- "{id: {from: 0, to: 4}, words: {contains: ['orange', 'bananna']}}": testQuery({id: {from: 0, to: 4}, words: {contains: ['orange', 'bananna']}}, [2]),
+ "{words: {contains: ['apple', 'banana']}}": testQuery({words: {contains: ['apple', 'banana']}}, []),
+ "{words: {contains: ['orange', 'banana']}}": testQuery({words: {contains: ['orange', 'banana']}}, [2]),
+ "{id: {from: 0, to: 4}, words: {contains: ['orange', 'banana']}}": testQuery({id: {from: 0, to: 4}, words: {contains: ['orange', 'banana']}}, [2]),
// "{name: '*e'}": testQuery({name: '*e'}, [5, 1, 3]), don't know if we even support this yet
"{id: {from: 1, to: 3}}, sort by name +": testQuery({id: {from: 1, to: 3}}, {sort:[{attribute: "name"}]}, [1, 3, 2]),
"{id: {from: 1, to: 3}}, sort by name -": testQuery({id: {from: 1, to: 3}}, {sort:[{attribute: "name", descending: true}]}, [2, 3, 1]),

0 comments on commit 508c215

Please sign in to comment.