Commit de376e14 authored by Vincent Bechu's avatar Vincent Bechu

[querystorage] Handle capacity schema.

parent 22b3e4fc
...@@ -47,7 +47,8 @@ ...@@ -47,7 +47,8 @@
var this_storage_capacity_list = ["limit", var this_storage_capacity_list = ["limit",
"sort", "sort",
"select", "select",
"query"]; "query",
"schema"];
if (this_storage_capacity_list.indexOf(name) !== -1) { if (this_storage_capacity_list.indexOf(name) !== -1) {
return true; return true;
...@@ -75,11 +76,14 @@ ...@@ -75,11 +76,14 @@
((options.select_list === undefined) || ((options.select_list === undefined) ||
(substorage.hasCapacity("select"))) && (substorage.hasCapacity("select"))) &&
((options.limit === undefined) || ((options.limit === undefined) ||
(substorage.hasCapacity("limit")))) { (substorage.hasCapacity("limit"))) &&
((options.schema === undefined) ||
(substorage.hasCapacity("schema")))) {
sub_options.query = options.query; sub_options.query = options.query;
sub_options.sort_on = options.sort_on; sub_options.sort_on = options.sort_on;
sub_options.select_list = options.select_list; sub_options.select_list = options.select_list;
sub_options.limit = options.limit; sub_options.limit = options.limit;
sub_options.schema = options.schema;
} }
} catch (error) { } catch (error) {
if ((error instanceof jIO.util.jIOError) && if ((error instanceof jIO.util.jIOError) &&
......
...@@ -400,7 +400,8 @@ ...@@ -400,7 +400,8 @@
(capacity === "sort") || (capacity === "sort") ||
(capacity === "select") || (capacity === "select") ||
(capacity === "limit") || (capacity === "limit") ||
(capacity === "query")) { (capacity === "query") ||
(capacity === "schema")) {
return true; return true;
} }
throw new Error("Unexpected " + capacity + " capacity check"); throw new Error("Unexpected " + capacity + " capacity check");
...@@ -410,7 +411,8 @@ ...@@ -410,7 +411,8 @@
sort_on: [["title", "ascending"]], sort_on: [["title", "ascending"]],
limit: [5], limit: [5],
select_list: ["title", "id"], select_list: ["title", "id"],
query: 'title: "two"' query: 'title: "two"',
schema: {'title': 'string'}
}, },
"buildQuery called"); "buildQuery called");
return "taboulet"; return "taboulet";
...@@ -429,7 +431,8 @@ ...@@ -429,7 +431,8 @@
sort_on: [["title", "ascending"]], sort_on: [["title", "ascending"]],
limit: [5], limit: [5],
select_list: ["title", "id"], select_list: ["title", "id"],
query: 'title: "two"' query: 'title: "two"',
schema: {'title': 'string'}
}) })
.then(function (result) { .then(function (result) {
deepEqual(result, { deepEqual(result, {
...@@ -823,6 +826,102 @@ ...@@ -823,6 +826,102 @@
}); });
}); });
test("manual query used if substorage does not handle schema", function () {
stop();
expect(4);
function StorageSchemaCapacity() {
return this;
}
StorageSchemaCapacity.prototype.get = function (id) {
var doc = {
title: id,
id: "ID " + id,
"another": "property"
};
if (id === "foo") {
equal(id, "foo", "Get foo");
doc.modification_date = "Fri, 08 Sep 2017 07:46:27 +0000";
} else {
equal(id, "bar", "Get bar");
doc.modification_date = "Thu, 07 Sep 2017 18:59:23 +0000";
}
return doc;
};
StorageSchemaCapacity.prototype.hasCapacity = function (capacity) {
if ((capacity === "list") ||
(capacity === "select") ||
(capacity === "limit")) {
return true;
}
return false;
};
StorageSchemaCapacity.prototype.buildQuery = function (options) {
deepEqual(options, {}, "No query parameter");
var result2 = [{
id: "foo",
value: {}
}, {
id: "bar",
value: {}
}];
return result2;
};
jIO.addStorage(
'querystoragenoschemacapacity',
StorageSchemaCapacity
);
var jio = jIO.createJIO({
type: "query",
sub_storage: {
type: "querystoragenoschemacapacity"
}
});
jio.allDocs({
sort_on: [["modification_date", "descending"]],
limit: [0, 5],
select_list: ['modification_date'],
schema: {
"modification_date": {
"type": "string",
"format": "date-time"
}
}
})
.then(function (result) {
deepEqual(result, {
data: {
rows: [
{
id: "foo",
doc: {},
value: {
modification_date: "Fri, 08 Sep 2017 07:46:27 +0000"
}
}, {
id: "bar",
doc: {},
value: {
modification_date: "Thu, 07 Sep 2017 18:59:23 +0000"
}
}
],
total_rows: 2
}
});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// queryStorage.repair // queryStorage.repair
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
......
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