mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Let LevelDB node handle json object (and binary) as well as text.
to close #626
This commit is contained in:
parent
a498bd16b5
commit
3fff2c404e
@ -1,16 +1,26 @@
|
||||
|
||||
<script type="text/x-red" data-template-name="leveldbase">
|
||||
<script type="text/html" data-template-name="leveldbase">
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-db"><i class="fa fa-briefcase"></i> Database</label>
|
||||
<input type="text" id="node-config-input-db" placeholder="database path/name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-encoding"><i class="fa fa-random"></i> Values are</label>
|
||||
|
||||
<select type="text" id="node-config-input-encoding">
|
||||
<option value="utf8">text</option>
|
||||
<option value="json">JSON</option>
|
||||
<option value="binary">binary</option>
|
||||
</select>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('leveldbase',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
db: {value:"",required:true}
|
||||
db: {value:"",required:true},
|
||||
encoding: {value:"utf8"}
|
||||
},
|
||||
label: function() {
|
||||
return this.db;
|
||||
@ -18,7 +28,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="leveldb in">
|
||||
<script type="text/html" data-template-name="leveldb in">
|
||||
<div class="form-row node-input-level">
|
||||
<label for="node-input-level"><i class="fa fa-briefcase"></i> Database</label>
|
||||
<input type="text" id="node-input-level">
|
||||
@ -29,7 +39,7 @@
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="leveldb in">
|
||||
<script type="text/html" data-help-name="leveldb in">
|
||||
<p>Uses <a href="https://code.google.com/p/leveldb/" target="_new"><i>LevelDB</i></a> for a simple key value pair database.</p>
|
||||
<p>Use this node to <b>get</b>, or retrieve the data already saved in the database.</p>
|
||||
<p><code>msg.topic</code> must hold the <i>key</i> for the database, and the result is returned in <code>msg.payload</code>.</p>
|
||||
@ -58,7 +68,7 @@
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/x-red" data-template-name="leveldb out">
|
||||
<script type="text/html" data-template-name="leveldb out">
|
||||
<div class="form-row node-input-level">
|
||||
<label for="node-input-level"><i class="fa fa-briefcase"></i> Database</label>
|
||||
<input type="text" id="node-input-level">
|
||||
@ -77,7 +87,7 @@
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/x-red" data-help-name="leveldb out">
|
||||
<script type="text/html" data-help-name="leveldb out">
|
||||
<p>Uses <a href="https://code.google.com/p/leveldb/" target="_new"><i>LevelDB</i></a> for a simple key value pair database.</p>
|
||||
<p>Use this node to either <b>put</b> (store) the <code>msg.payload</code> to the named database file, using <code>msg.topic</code> as the key.</p>
|
||||
<p>To <b>delete</b> information select delete in the properties dialogue and again use <code>msg.topic</code> as the key.</b>.</p>
|
||||
|
@ -6,9 +6,10 @@ module.exports = function(RED) {
|
||||
function LevelNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.dbname = n.db;
|
||||
this.encoding = n.encoding || "utf8";
|
||||
this.ready = false;
|
||||
var node = this;
|
||||
lvldb(this.dbname, function(err, db) {
|
||||
lvldb(this.dbname, {valueEncoding:this.encoding}, function(err, db) {
|
||||
if (err) { node.error(err); }
|
||||
node.db = db;
|
||||
node.db.on('ready', function() { node.ready = true; });
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-leveldb",
|
||||
"version" : "0.2.0",
|
||||
"version" : "0.3.0",
|
||||
"description" : "A Node-RED node to read and write to a LevelDB database",
|
||||
"dependencies" : {
|
||||
"level" : "^6.0.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user