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;

沒有留言:

張貼留言

2026 作業3 RFID+ Telegram 練習

 2026 作業3  RFID+ Telegram  練習 (Wokwi 與 Telegram 二者溝通訊息反映比較慢 ) 歡迎 Alex 使用 RFID 控制系統 /on : 開啟 LED /off : 關閉 LED /flash : 閃爍模式 /timer : 開啟 5 秒 ...