Commit 82fd960e authored by Vincent Bechu's avatar Vincent Bechu Committed by Aurel

mapping storage: add property include_docs and fix put

parent 0c0a7194
...@@ -14,7 +14,10 @@ ...@@ -14,7 +14,10 @@
option.query = this._mapping_dict.id.equal + ': "' + index + '"'; option.query = this._mapping_dict.id.equal + ': "' + index + '"';
return this._sub_storage.allDocs(option) return this._sub_storage.allDocs(option)
.push(function (data) { .push(function (data) {
return data.data.rows[0].id; if (data.data.rows.length > 0) {
return data.data.rows[0].id;
}
return undefined;
}); });
}; };
...@@ -51,7 +54,7 @@ ...@@ -51,7 +54,7 @@
}; };
MappingStorage.prototype.put = function (index, doc) { MappingStorage.prototype.put = function (index, doc) {
var prop, var prop, that = this,
doc_mapped = JSON.parse(JSON.stringify(this._default_dict)); doc_mapped = JSON.parse(JSON.stringify(this._default_dict));
for (prop in doc) { for (prop in doc) {
if (doc.hasOwnProperty(prop)) { if (doc.hasOwnProperty(prop)) {
...@@ -63,9 +66,15 @@ ...@@ -63,9 +66,15 @@
return this._sub_storage.put(index, doc_mapped); return this._sub_storage.put(index, doc_mapped);
} }
doc_mapped[this._mapping_dict.id.equal] = index; doc_mapped[this._mapping_dict.id.equal] = index;
return this._sub_storage.post(doc_mapped) return this._getSubStorageId(index)
.push(function () { .push(function (id) {
return index; if (id === undefined) {
return that._sub_storage.post(doc_mapped)
.push(function () {
return index;
});
}
return that._sub_storage.put(id, doc_mapped);
}); });
}; };
...@@ -130,12 +139,15 @@ ...@@ -130,12 +139,15 @@
}); });
}; };
MappingStorage.prototype.hasCapacity = function () { MappingStorage.prototype.hasCapacity = function (name) {
if (name === "include_docs") {
return true;
}
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments); return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
}; };
MappingStorage.prototype.buildQuery = function (option) { MappingStorage.prototype.buildQuery = function (option) {
var that = this, i, select_list = [], sort_on = [], query; var that = this, i, select_list = [], sort_on = [], query, prop;
function mapQuery(one_query) { function mapQuery(one_query) {
var i, query_list = []; var i, query_list = [];
...@@ -167,6 +179,14 @@ ...@@ -167,6 +179,14 @@
select_list.push(this._mapping_dict[option.select_list[i]].equal); select_list.push(this._mapping_dict[option.select_list[i]].equal);
} }
} }
if (option.include_docs) {
select_list = [];
for (prop in this._mapping_dict) {
if (this._mapping_dict.hasOwnProperty(prop)) {
select_list.push(this._mapping_dict[prop].equal);
}
}
}
if (this._mapping_dict.id !== undefined if (this._mapping_dict.id !== undefined
&& this._mapping_dict.id.equal !== "id") { && this._mapping_dict.id.equal !== "id") {
select_list.push(this._mapping_dict.id.equal); select_list.push(this._mapping_dict.id.equal);
...@@ -177,8 +197,7 @@ ...@@ -177,8 +197,7 @@
query: mapQuery(query), query: mapQuery(query),
select_list: select_list, select_list: select_list,
sort_on: sort_on, sort_on: sort_on,
limit: option.limit, limit: option.limit
include_docs: option.include_docs || false
} }
) )
.push(function (result) { .push(function (result) {
......
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