Commit 8edeb390 authored by Romain Courteaud's avatar Romain Courteaud

IDB: remove qyery handling

parent 62bcd6c6
......@@ -46,7 +46,7 @@
DOMError, Event, Set, parseStringToObject*/
(function (indexedDB, jIO, RSVP, Blob, Math, IDBKeyRange, IDBOpenDBRequest,
DOMError, parseStringToObject) {
DOMError) {
"use strict";
// Read only as changing it can lead to data corruption
......@@ -270,10 +270,7 @@
IndexedDBStorage.prototype.buildQuery = function (options) {
var result_list = [],
context = this,
query,
key,
value;
context = this;
function pushIncludedMetadata(cursor) {
result_list.push({
......@@ -295,20 +292,15 @@
return waitForOpenIndexedDB(context, function (db) {
return waitForTransaction(db, ["metadata"], "readonly",
function (tx) {
key = "_id";
if (options.subquery) {
query = parseStringToObject(options.subquery);
key = INDEX_PREFIX + query.key;
value = IDBKeyRange.only(query.value);
}
var key = "_id";
if (options.include_docs === true) {
return waitForAllSynchronousCursor(
tx.objectStore("metadata").index(key).openCursor(value),
tx.objectStore("metadata").index(key).openCursor(),
pushIncludedMetadata
);
}
return waitForAllSynchronousCursor(
tx.objectStore("metadata").index(key).openKeyCursor(value),
tx.objectStore("metadata").index(key).openKeyCursor(),
pushMetadata
);
});
......@@ -734,5 +726,4 @@
};
jIO.addStorage("indexeddb", IndexedDBStorage);
}(indexedDB, jIO, RSVP, Blob, Math, IDBKeyRange, IDBOpenDBRequest, DOMError,
parseStringToObject));
}(indexedDB, jIO, RSVP, Blob, Math, IDBKeyRange, IDBOpenDBRequest, DOMError));
......@@ -52,182 +52,6 @@
});
}
function idCompare(value1, value2) {
if (value1.id > value2.id) {
return 1;
}
if (value1.id < value2.id) {
return -1;
}
return 0;
}
/////////////////////////////////////////////////////////////////
// indexedDBStorage.buildQuery
/////////////////////////////////////////////////////////////////
module("indexedDBStorage.buildQuery", {
teardown: function () {
deleteIndexedDB(this.jio);
}
});
test("Simple query matching single object", function () {
var context = this;
context.jio = jIO.createJIO({
type: "indexeddb",
database: "index2_test",
index_key_list: ["a", "b"],
});
stop();
expect(2);
context.jio.put("32", {"a": "3", "b": "2"})
.then(function () {
return context.jio.allDocs({subquery: 'a: "3"'});
})
.then(function (result) {
equal(result.data.total_rows, 1);
deepEqual(result.data.rows, [{"id": "32", "value": {}}]);
})
.fail(function (error) {
console.log(error);
})
.always(function () {
start();
});
});
test("Simple query matching multiple objects", function () {
var context = this;
context.jio = jIO.createJIO({
type: "indexeddb",
database: "index2_test",
index_key_list: ["a", "b"],
});
stop();
expect(2);
RSVP.all([
context.jio.put("32", {a: "3", b: "1"}),
context.jio.put("21", {a: "8", b: "1"}),
context.jio.put("3", {a: "5", b: "1"})
])
.then(function () {
return context.jio.allDocs({subquery: 'b: "1"'});
})
.then(function (result) {
equal(result.data.total_rows, 3);
deepEqual(result.data.rows.sort(idCompare),
[
{"id": "32", "value": {}},
{"id": "21", "value": {}},
{"id": "3", "value": {}}
].sort(idCompare));
})
.fail(function (error) {
console.log(error);
})
.always(function () {
start();
});
});
test("Index keys are modified", function () {
var context = this;
context.jio = jIO.createJIO({
type: "indexeddb",
database: "index2_test",
version: 1,
index_key_list: ["a"]
});
stop();
expect(7);
RSVP.all([
context.jio.put("32", {"a": "3", "b": "2", "c": "inverse"}),
context.jio.put("5", {"a": "6", "b": "2", "c": "strong"}),
context.jio.put("14", {"a": "67", "b": "3", "c": "disolve"})
])
.then(function () {
return context.jio.allDocs({subquery: 'a: "67"'});
})
.then(function (result) {
deepEqual(result.data.rows, [{"id": "14", "value": {}}]);
})
.then(function () {
context.jio = jIO.createJIO({
type: "indexeddb",
database: "index2_test",
version: 2,
index_key_list: ["a", "b", "c"],
});
})
.then(function () {
return RSVP.all([
context.jio.put("18", {"a": "2", "b": "3", "c": "align"}),
context.jio.put("62", {"a": "3", "b": "2", "c": "disolve"})
]);
})
.then(function () {
return context.jio.allDocs({subquery: 'b: "3"'});
})
.then(function (result) {
deepEqual(result.data.rows, [{"id": "14", "value": {}},
{"id": "18", "value": {}}]);
})
.then(function () {
return context.jio.allDocs({subquery: 'c: "disolve"'});
})
.then(function (result) {
deepEqual(result.data.rows, [{"id": "14", "value": {}},
{"id": "62", "value": {}}]);
})
.then(function () {
return context.jio.allDocs({subquery: 'a: "3"'});
})
.then(function (result) {
deepEqual(result.data.rows, [{"id": "32", "value": {}},
{"id": "62", "value": {}}]);
})
.then(function () {
context.jio = jIO.createJIO({
type: "indexeddb",
database: "index2_test",
index_key_list: ["a", "c"],
version: 3
});
})
.then(function () {
return context.jio.put("192", {"a": "3", "b": "3", "c": "disolve"});
})
.then(function () {
return context.jio.allDocs({subquery: 'a: "3"'});
})
.then(function (result) {
deepEqual(result.data.rows.sort(idCompare), [{"id": "192", "value": {}},
{"id": "32", "value": {}}, {"id": "62", "value": {}}]);
})
.then(function () {
return context.jio.allDocs({query: 'c: "disolve"'});
})
.then(function (result) {
deepEqual(result.data.rows.sort(idCompare), [{"id": "14", "value": {}},
{"id": "192", "value": {}}, {"id": "62", "value": {}}]);
})
.then(function () {
return context.jio.allDocs({subquery: 'b: "3"'});
})
.fail(function (error) {
equal(error.status_code, 501);
equal(error.message,
"Capacity 'query' is not implemented on 'indexeddb'");
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// indexeddbStorage.constructor
/////////////////////////////////////////////////////////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment