Initial upload.

This commit is contained in:
kolban
2016-03-04 11:04:16 -06:00
commit 432a989802
7 changed files with 185 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/node_modules/
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>node-red-contrib-couchdb</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
+79
View File
@@ -0,0 +1,79 @@
<!--
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.
-->
<script type="text/javascript">
RED.nodes.registerType('couchdb',{
// node definition
category: "storage",
inputs: 1,
outputs: 1,
icon: "db.png",
color: "#3FADB5",
label: function () {
return this.name || "couchdb"
},
paletteLabel: "couchdb",
defaults: {
name: {
value: ""
},
serverUrl: {
value: "",
required: true
},
database: {
value: "",
required: true
},
retrievalType: {
value: "byId"
}
}
});
</script>
<script type="text/x-red" data-help-name="couchdb">
<p>A node for searching documents in a couchdb database.</p>
<p>Searching for documents can be done in a few modes. Directly by using the documents
<b>_id</b> or by using a key lookup in a view.</p>
<p>When querying using the <b>_id</b> option, the value for the documents <code>_id</code>
should be passed in the <code>msg.payload</code> as a string.</p>
<p>The database name must follow these rules:
<ul>
<li>No spaces</li>
<li>All letters in lower case</li>
<li>The first character must not be <code>_</code></li>
</ul>
</p>
</script>
<script type="text/x-red" data-template-name="couchdb">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-serverUrl"><i class="icon-tasks"></i> Server URL</label>
<input type="text" id="node-input-serverUrl" placeholder="Server URL">
</div>
<div class="form-row">
<label for="node-input-database"><i class="icon-tasks"></i> Database</label>
<input type="text" id="node-input-database" placeholder="Database">
</div>
<div class="form-row">
<label for="node-input-retrievalType"><i class="icon-tasks"></i> Retrieval Type</label>
<input type="text" id="node-input-retrievalType" placeholder="Retrieval Type">
</div>
</script>
+54
View File
@@ -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
+3
View File
@@ -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
+23
View File
@@ -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 <kolban@us.ibm.com>",
"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"
}
}
+14
View File
@@ -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));
}