From 432a98980219805eac0c2141174df327b1507a84 Mon Sep 17 00:00:00 2001 From: kolban Date: Fri, 4 Mar 2016 11:04:16 -0600 Subject: [PATCH] Initial upload. --- .gitignore | 1 + .project | 11 +++++++ couchdb.html | 79 ++++++++++++++++++++++++++++++++++++++++++++++ couchdb.js | 54 +++++++++++++++++++++++++++++++ install.bat | 3 ++ package.json | 23 ++++++++++++++ tests/test-nano.js | 14 ++++++++ 7 files changed, 185 insertions(+) create mode 100644 .gitignore create mode 100644 .project create mode 100644 couchdb.html create mode 100644 couchdb.js create mode 100644 install.bat create mode 100644 package.json create mode 100644 tests/test-nano.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ccbe46 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules/ diff --git a/.project b/.project new file mode 100644 index 0000000..9c99b85 --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + node-red-contrib-couchdb + + + + + + + + diff --git a/couchdb.html b/couchdb.html new file mode 100644 index 0000000..ecd3653 --- /dev/null +++ b/couchdb.html @@ -0,0 +1,79 @@ + + + + + + \ No newline at end of file diff --git a/couchdb.js b/couchdb.js new file mode 100644 index 0000000..f8e11d2 --- /dev/null +++ b/couchdb.js @@ -0,0 +1,54 @@ +/** + * Copyright 2015 Neil Kolban. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +/** + * Implement a CoachDB accessor within a Node-RED environment. + * The configuration parameters for the node are: + * * serverUrl - The URL to reach the CouchDB server ... eg. http://localhost:5984 + * * database - The name of the database + * * retrievalType - How we should retrieve a document + * * byId + * * ??? + * This module makes extensive use of the project called "dscape/nano" + * found on Github at: + * + * https://github.com/dscape/nano + * + * + */ +module.exports = function(RED) { + function CouchDBNode(config) { + console.log("CouchDBNode: config: " + JSON.stringify(config)); + var thisNode = this; + var nano = require("nano")(config.serverUrl); + var db = nano.use(config.database); + this.on('input', function(msg) { + // Process the request here + db.get(msg.payload, function(err, body) { + console.log("We got a document: " + body); + if (!err) { + msg.payload = body; + thisNode.send(msg); + } + }); + console.log("Process message: " + JSON.stringify(msg)); + }); + RED.nodes.createNode(thisNode, config); + } // End of couchDBNode definition + + RED.nodes.registerType("couchdb", CouchDBNode); +} +// End of file \ No newline at end of file diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..09ad5f5 --- /dev/null +++ b/install.bat @@ -0,0 +1,3 @@ +copy package.json C:\Users\kolban\.node-red\node_modules\node-red-contrib-couchdb +copy couchdb.html C:\Users\kolban\.node-red\node_modules\node-red-contrib-couchdb +copy couchdb.js C:\Users\kolban\.node-red\node_modules\node-red-contrib-couchdb \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..d771d0c --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name" : "node-red-contrib-couchdb", + "version" : "0.0.1", + "description" : "A node-red couchdb node", + "license" : "Apache-2.0", + "dependencies": { + "nano": "^6.2.0" + }, + "author": "Neil Kolban ", + "keywords": [ "node-red", "couchdb", "ibm" ], + "node-red" : { + "nodes": { + "couchdb": "couchdb.js" + } + }, + "repository": { + "type": "git", + "url": "https://github.com/nkolban/node-red-contrib-couchdb" + }, + "engines": { + "node": ">=0.10" + } +} \ No newline at end of file diff --git a/tests/test-nano.js b/tests/test-nano.js new file mode 100644 index 0000000..0299ec2 --- /dev/null +++ b/tests/test-nano.js @@ -0,0 +1,14 @@ +// Test our understanding of nano +var docId = "56d8e35efaa2604f06173dc5"; + +var nano = require("nano")("http://localhost:5984"); +var test1 = nano.use("test1"); +test1.get(docId, function(err, body, header) { + dump(err, body, header); + console.log("Got something!"); +}); +console.log("test-nanon: Core completed"); + +function dump(err, body, header) { + console.log("err: " + JSON.stringify(err) + "\nbody: " + JSON.stringify(body) + "\nheader: " + JSON.stringify(header)); +} \ No newline at end of file