From 27e33fe9d4055551441f67de9697676742f2bfa4 Mon Sep 17 00:00:00 2001 From: Rune Lien Date: Fri, 7 Jun 2013 01:19:34 +0200 Subject: [PATCH 1/5] Added clause to not put default views into design doc when indexes is top level. E.g used in cloudant to make search/lucene indexes --- lib/cradle/database/documents.js | 10 +++++++--- package.json | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/cradle/database/documents.js b/lib/cradle/database/documents.js index d01ffe0..47ba585 100644 --- a/lib/cradle/database/documents.js +++ b/lib/cradle/database/documents.js @@ -53,6 +53,7 @@ Database.prototype.get = function (id, rev) { Database.prototype.put = function (id, doc, callback) { var cache = this.cache; if (typeof(id) !== 'string') { throw new(TypeError)("id must be a string") } + console.log(doc, 'doc to put') this.query({ method: 'PUT', path: cradle.escape(id), @@ -113,9 +114,12 @@ Database.prototype._save = function (id, rev, doc, callback) { // PUT a single document, with an id (Create or Update) if (id) { // Design document - if (/^_design\/(\w|%|\-)+$/.test(id) && !('views' in doc)) { - document.language = "javascript"; - document.views = doc; + if (/^_design\/(\w|%|\-)+$/.test(id) && !('views' in doc) ) { + if(!doc.indexes){ + document.language = "javascript"; + document.views = doc; + } + } else { document = doc; } diff --git a/package.json b/package.json index e76609b..0e40288 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cradle", - "version": "0.6.6", + "version": "0.6.7", "description": "the high-level, caching, CouchDB library", "url": "http://cloudhead.io/cradle", "keywords": ["couchdb", "database", "couch"], From 80283fa0d5d1661ea8d7e87571ab48fd09f60261 Mon Sep 17 00:00:00 2001 From: Rune Lien Date: Fri, 7 Jun 2013 09:14:50 +0200 Subject: [PATCH 2/5] Fixed test for index search, whitespace and removed console statements --- .gitignore | 3 ++- lib/cradle/database/documents.js | 7 +++---- test/database-test.js | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 28a59dc..f3ba0ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules npm-debug.log test/fixtures/README.md -test/fixtures/not-found.txt \ No newline at end of file +test/fixtures/not-found.txt +.idea \ No newline at end of file diff --git a/lib/cradle/database/documents.js b/lib/cradle/database/documents.js index 47ba585..752777e 100644 --- a/lib/cradle/database/documents.js +++ b/lib/cradle/database/documents.js @@ -53,7 +53,6 @@ Database.prototype.get = function (id, rev) { Database.prototype.put = function (id, doc, callback) { var cache = this.cache; if (typeof(id) !== 'string') { throw new(TypeError)("id must be a string") } - console.log(doc, 'doc to put') this.query({ method: 'PUT', path: cradle.escape(id), @@ -96,7 +95,6 @@ Database.prototype.save = function (/* [id], [rev], doc | [doc, ...] */) { Database.prototype._save = function (id, rev, doc, callback) { var options = this.connection.options; var document = {}, that = this; - // Bulk Insert if (Array.isArray(doc)) { document.docs = doc; @@ -115,11 +113,12 @@ Database.prototype._save = function (id, rev, doc, callback) { if (id) { // Design document if (/^_design\/(\w|%|\-)+$/.test(id) && !('views' in doc) ) { - if(!doc.indexes){ + if( !doc.indexes ){ document.language = "javascript"; document.views = doc; + } else { + document.indexes = doc.indexes } - } else { document = doc; } diff --git a/test/database-test.js b/test/database-test.js index 64cf135..b6a4061 100644 --- a/test/database-test.js +++ b/test/database-test.js @@ -71,6 +71,22 @@ function shouldQueryCouch(name) { }, "creates a new document (201)": macros.status(201) }, + "with indexes as root node" : { + topic: function (db) { + db.save('_design/search_couch_lucene', { + indexes: { + search_view:{ + index: function(doc){index('default', doc.name); + } + } + } + }, this.callback); + }, + "creates a new document (201)": macros.status(201), + "returns the revision": function (res) { + assert.ok(res.rev); + } + }, "with a '_design' id": { topic: function (db) { db.save('_design/horses', { From 5a5ad224a4107a13fc1a6420f2716130961f1e51 Mon Sep 17 00:00:00 2001 From: Rune Lien Date: Fri, 7 Jun 2013 23:10:36 +0200 Subject: [PATCH 3/5] Bumped by accident, should have been kept locally --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e40288..e76609b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cradle", - "version": "0.6.7", + "version": "0.6.6", "description": "the high-level, caching, CouchDB library", "url": "http://cloudhead.io/cradle", "keywords": ["couchdb", "database", "couch"], From 16eca2c32fb6adc8dab37c8804edd71924b73afc Mon Sep 17 00:00:00 2001 From: Rune Lien Date: Fri, 7 Jun 2013 23:22:03 +0200 Subject: [PATCH 4/5] 4 space soft indent --- lib/cradle/database/documents.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cradle/database/documents.js b/lib/cradle/database/documents.js index 752777e..0491d1a 100644 --- a/lib/cradle/database/documents.js +++ b/lib/cradle/database/documents.js @@ -113,12 +113,12 @@ Database.prototype._save = function (id, rev, doc, callback) { if (id) { // Design document if (/^_design\/(\w|%|\-)+$/.test(id) && !('views' in doc) ) { - if( !doc.indexes ){ - document.language = "javascript"; - document.views = doc; - } else { - document.indexes = doc.indexes - } + if( !doc.indexes ){ + document.language = "javascript"; + document.views = doc; + } else { + document.indexes = doc.indexes + } } else { document = doc; } From b2113a7818d6592de9c1f649b2e9d95814651510 Mon Sep 17 00:00:00 2001 From: Rune Lien Date: Fri, 7 Jun 2013 23:34:03 +0200 Subject: [PATCH 5/5] Naming confusion --- test/database-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/database-test.js b/test/database-test.js index b6a4061..6b5a99d 100644 --- a/test/database-test.js +++ b/test/database-test.js @@ -75,7 +75,7 @@ function shouldQueryCouch(name) { topic: function (db) { db.save('_design/search_couch_lucene', { indexes: { - search_view:{ + search_name:{ index: function(doc){index('default', doc.name); } }