0

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)?

mpen
  • 272,448
  • 266
  • 850
  • 1,236

2 Answers2

1

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 )

Andrey Sidorov
  • 24,905
  • 4
  • 62
  • 75
0

With js Date objects you can do (+yourDate) to have the corresponding number (in ms) and (yourDate/1000) to have an unix time like number.

For example

> var a = new Date()
< Mon May 15 2017 22:25:08 GMT+0200 (CEST)

> +a
< 1494879908154

> (a/1000)
< 1494879908.154
max-lt
  • 1,037
  • 10
  • 12