bestlong / node-red-contrib-mssql-plus

A Node-RED node to read and write to Microsoft MS SQL Databases
MIT License
32 stars 18 forks source link

Column parameters in bulk insert #100

Open Webastian opened 3 months ago

Webastian commented 3 months ago

Can someone explain to me how I can pass column parameters to the node in bulk insert mode. Because the number of columns and column names of my data are dynamic, I cannot define them permanently via the editor. I would be grateful for a small example. It would certainly also be useful for others if the example were in the readme or bulk demo.

Webastian commented 1 month ago

Here is how I implemented it

I use a function like this to create the parameters

function createColParameter(s) {
    var cols = [];
    cols.push(JSON.parse('{ "output": false, "name": "Timestamp", "type": "DateTime", "options": { "nullable": false } }'));

    for (var i = 0; i < s.length; i++) {
       cols.push(JSON.parse('{ "output": false, "name": "' + s[i] + '", "type": "Real", "options": { "nullable": true }}'));
    }
    return cols;
}

flow.set("ColParams", createColParameter(colnames));

In the node 'MSSQL' I use: Parameters: flow.ColParams