Search code examples
mysqlnode.jsnode-mysqlnode-mysql2

How to override how Dates are escaped?


I'm using node-mysql2. I want to override how JavaScript Date objects are escaped.

By default, they are converted to 'YYYY-mm-dd HH:ii:ss' strings, but I want to store them as integers instead.

How can I do this without reimplementing the entire queryFormat function (which parses out ? and :namedPlaceholders)?


Solution

  • Not possible currently, you'll have to explicitly convert your data before passing as parameters to a query or prepared statement. Might be a good feature - feel free to send pr if you implement it to yourself ( there is already a way to do opposite via custom typeCast function - https://github.com/mysqljs/mysql#type-casting )