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;

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...