Node Mysql Insert and Modify shorthand from object with 1 conversion

Viewed 124

There is a very useful shorthand for Node Mysql where it automatically spreads all object values as column values like this:

'INSERT INTO `table` SET ? ;', [someobject]

or

'UPDATE `table` set ? WHERE id = ?',[someobject,id]

This is very handy as it allow for maintainable code with very large objects (30+ columns)

But one of the columns is a Timestamp value in Mysql and the data on the node app is as a Linux timestamp (integer), Mysql doesn't automatically map this integer. I usually do something like : FROM_UNIXTIME(?) to automatically convert this to a full date string on the (database) server.

How can I keep this shorthand technique with a timestamp insertion? I could modify this parameter beforehand in node, but nothing guarantees me the node server and the database are on the same timezone.

0 Answers
Related