I am creating table in a database, originally it was one long line ,
I wanted to make it clearer to understand as I do not like one long line of text.
I have made a function node with this, it works but is there a better and neater way
As I have lots of commas and pluses ?
msg.payload =
"CREATE TABLE sensors (" +
"serial_no SERIAL PRIMARY KEY," +
"device TEXT not null," +
"device_data JSON not null );"
return msg;
I like to use the template node for blocks of text like this -- any text you put into the multi-line editor will be added to msg.payload with the newlines intact. And since SQL statements can contain newlines, this should just work without using any javascript code.
Please note that this is NOT the ui_template node... and if you want to insert incoming msg values into your text, it also support moustache (sic ;*) syntax like {{payload.tablename}}.
True - what you see is what you get... but if you do use "mustache" syntax to insert data into that DDL string, don't forget to use the triple braces i.e. {{{payload.tablename}}} to stop any potential html character encoding!