mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Let sqlite open RO as well as RW
Also better reuse of connection object
This commit is contained in:
parent
f3b0e2277d
commit
211988017f
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-red-node-sqlite",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.2",
|
||||
"description": "A sqlite node for Node-RED",
|
||||
"dependencies": {
|
||||
"sqlite3": "^4.0.2"
|
||||
|
@ -4,13 +4,24 @@
|
||||
<label for="node-config-input-db"><i class="fa fa-database"></i> Database</label>
|
||||
<input type="text" id="node-config-input-db" placeholder="/tmp/sqlite">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-mode">Mode</label>
|
||||
<select id="node-config-input-mode" style="width:70%">
|
||||
<option value="RWC">Read-Write-Create</option>
|
||||
<option value="RW">Read-Write</option>
|
||||
<option value="RO">Read-Only</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-tips"><b>Note</b>: Setting the database name to <code>:memory:</code>
|
||||
will create a non-persistant in memory database.</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('sqlitedb',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
db: {value:"",required:true}
|
||||
db: {value:"", required:true},
|
||||
mode: {value:"RWC"}
|
||||
},
|
||||
label: function() {
|
||||
return this.db;
|
||||
|
@ -7,10 +7,14 @@ module.exports = function(RED) {
|
||||
RED.nodes.createNode(this,n);
|
||||
|
||||
this.dbname = n.db;
|
||||
this.mod = n.mode;
|
||||
if (n.mode === "RWC") { this.mode = sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE; }
|
||||
if (n.mode === "RW") { this.mode = sqlite3.OPEN_READWRITE; }
|
||||
if (n.mode === "RO") { this.mode = sqlite3.OPEN_READONLY; }
|
||||
var node = this;
|
||||
|
||||
node.doConnect = function() {
|
||||
node.db = new sqlite3.Database(node.dbname);
|
||||
node.db = node.db || new sqlite3.Database(node.dbname,node.mode);
|
||||
node.db.on('open', function() {
|
||||
if (node.tick) { clearTimeout(node.tick); }
|
||||
node.log("opened "+node.dbname+" ok");
|
||||
@ -41,6 +45,7 @@ module.exports = function(RED) {
|
||||
|
||||
if (this.mydbConfig) {
|
||||
this.mydbConfig.doConnect();
|
||||
node.status({fill:"green",shape:"dot",text:this.mydbConfig.mod});
|
||||
var bind = [];
|
||||
node.on("input", function(msg) {
|
||||
if (this.sqlquery == "msg.topic"){
|
||||
|
Loading…
x
Reference in New Issue
Block a user