Using node-red-node-mysql v1.0.3, a simple INSERT - msg.topic = "insert into test (temperature) values (24.3)"
The table has an auto-increment primary key - id.
I need to know the id of the inserted record.
If I feed the MySQL output into a debug node it just shows ResultSetHeader "[object Object]"
Thanks @yOyOeK1 Yes I can get the most recent record inserted with a seperate query, I currently use select max(id) from test
But this is not ideal. Apart from needing an extra query, let's say my INSERT failed for some reason, select max(id) from text will give me the previous record and subsequent processing will be based on the wrong data. So I need to catch errors too.
I think the mysql node could/ought to return some useful info after an insert.
@jbudd you know that getting a id after insert is not a normal behaviors of any mysql driver. In this case it's the same. But I checked and mysql node is returning after insert a payload['insertId'] you don't have it ?
Check your debug node is it set to output "complete msg object"?
I think the reason is that the underlying MySQL library returns a "Result Object" type rather than a plain object so the debug node doesn't know how to handle it exactly. eg see Node.js MySQL Result Object - Examples.
So the data is all there - just the debug doesn't show it directly.