Hi guys, the existing DuckDB node in Node-RED is broken.
How can I do the same with a function node?
Here is an example, but when i try it again, the Node-RED will broken down. The log information said that [error] Error: IO Error: Cannot open file "demo.duckdb"
[
{
"id": "f7d4d3866eecb39f",
"type": "function",
"z": "c86c4b4c464dad69",
"name": "function 2",
"func": "// 2. 主函数(IIFE)\n(async () => {\n // 2.1 创建/打开数据库(磁盘文件)\n const db = await duckdbNodeApi.DuckDBInstance.create('demo.duckdb', { threads: '4' });\n const conn = await db.connect();\n\n // 2.2 建表\n await conn.run(`\n CREATE OR REPLACE TABLE users (\n id INTEGER,\n name VARCHAR,\n age INTEGER\n )\n `);\n\n // 2.3 准备批量插入\n const appender = await conn.createAppender('users');\n const rows = [\n [4, 'ddac', 45]\n ];\n for (const [id, name, age] of rows) {\n appender.appendInteger(id);\n appender.appendVarchar(name);\n appender.appendInteger(age);\n appender.endRow();\n }\n appender.flushSync(); // 立即落盘\n appender.closeSync();\n\n // 2.4 查询\n const reader = await conn.runAndReadAll(\n 'SELECT * FROM users WHERE age > 30 ORDER BY age DESC'\n );\n\n // 2.5 输出结果(JSON 形式)\n console.log(reader.getRowObjectsJson());\n\n // 2.6 清理\n await conn.disconnectSync();\n await db.duckdb_\n})();\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [
{
"var": "duckdbNodeApi",
"module": "@duckdb/node-api"
}
],
"x": 260,
"y": 80,
"wires": [
[]
]
}
]