DuckDB Flow Example
Node-RED and DuckDB have become an exceptional combination, allowing the use of quick coding techniques to configure, cache, and modify flows dynamically. This synergy facilitates a seamless transition from rapid prototyping to production, simplifying the development process. With AI snippets, you can also store WASM files generated by Go, Rust, C, C++, and more, adding a robust layer of functionality to your workflows.
[{"id":"b0b08215ec18023f","type":"tab","label":"DuckDB Demo","disabled":false,"info":"","env":[]},{"id":"103c148028ec5ce9","type":"group","z":"b0b08215ec18023f","name":"Response","style":{"label":true},"nodes":["f57825b6b5ae5b85","f755ca17a930136d"],"x":74,"y":399,"w":492,"h":82},{"id":"5d3acbe7571e32c6","type":"group","z":"b0b08215ec18023f","name":"Setup","style":{"label":true},"nodes":["10f8ec49d290906f","ce2b7cd6bf125293"],"x":74,"y":99,"w":452,"h":82},{"id":"e0fa50cbb46b7a95","type":"group","z":"b0b08215ec18023f","name":"Prepared SQL Statement","style":{"label":true},"nodes":["70d7e4a8ce02d25c"],"x":74,"y":239,"w":312,"h":82},{"id":"9310cf5c61848e0e","type":"catch","z":"b0b08215ec18023f","name":"Catch on All nodes","scope":null,"uncaught":false,"x":170,"y":40,"wires":[[]]},{"id":"10f8ec49d290906f","type":"function","z":"b0b08215ec18023f","g":"5d3acbe7571e32c6","name":"On Start - Load DuckDB","func":"return msg","outputs":1,"timeout":0,"noerr":0,"initialize":"var database = new duckdb.Database(':memory:');\ndatabase = database.connect()\nglobal.set('db', database)\n\n\n","finalize":"","libs":[{"var":"duckdb","module":"duckdb"}],"x":390,"y":140,"wires":[["70d7e4a8ce02d25c"]]},{"id":"ce2b7cd6bf125293","type":"http in","z":"b0b08215ec18023f","g":"5d3acbe7571e32c6","name":"GET /duckdb","url":"/duckdb","method":"get","upload":false,"swaggerDoc":"","x":170,"y":140,"wires":[["10f8ec49d290906f"]],"info":"Magic Is Real"},{"id":"f57825b6b5ae5b85","type":"http response","z":"b0b08215ec18023f","g":"103c148028ec5ce9","name":"HTTP Response","statusCode":"","headers":{"content-type":"text/html"},"x":460,"y":440,"wires":[]},{"id":"70d7e4a8ce02d25c","type":"function","z":"b0b08215ec18023f","g":"e0fa50cbb46b7a95","name":"Prepared Statment/ Insert Data","func":"global.get(\"db\").run('CREATE TABLE a (i INTEGER)');\nvar stmt = global.get(\"db\").prepare('INSERT INTO a VALUES (?)');\nfor (var i = 0; i < 10; i++) {\n stmt.run(i);\n}\nstmt.finalize();\n\nglobal.get(\"db\").all('SELECT * FROM a', function(err, res) {\n if (err) {\n console.warn(err);\n }\n msg.payload.dbresults = JSON.stringify(res)\n node.send(msg)\n});\n\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":280,"wires":[["f755ca17a930136d"]]},{"id":"f755ca17a930136d","type":"template","z":"b0b08215ec18023f","g":"103c148028ec5ce9","name":"Mustache Template Output","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"DuckDB Snapshot: {{payload.dbresults}} !","output":"str","x":220,"y":440,"wires":[["f57825b6b5ae5b85"]]}]