2019年12月8日 星期日

Node-RED insert and select using binding

Database examples - insert and select using binding


A selection of database examples. How you can manipulate the message topic and payload in various ways to get or insert data into a database. Includes bind columns, getting data directly from an input, converting automatically, templates etc. Examples are in SQLite but can be in MySQL or Postgres. Database table = "CREATE TABLE test (id INTEGER, text VARCHAR);".




CREATE TABLE RFIDtable( id INT PRIMARY KEY NOT NULL, currenttime TEXT , uidname TEXT)


INSERT Function 
-----------------------------------------------------------
msg.topic = "INSERT INTO RFIDtable (id,currenttime, uidname) VALUES (?,?,?)";
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();

if(h<10)
{
    
  h = '0'+h;

}

if(m<10)
{
    
  m = '0' + m;

}

if(s<10)
{
    
  s = '0' + s;

}

var hms= h + ':' + m + ':' + s ;
var id= Date.now() ;
msg.payload = [id ,hms, msg.payload];
return msg;

-----------------------------------------------------------


View Data

SELECT * FROM RFIDtable ORDER BY  id  DESC LIMIT 100;

沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...