gx0r/connect-session-knex

MySQL: Error on touch with Datetime ISO

gabrielalan opened this issue · 1 comments

Hello.

First, thank you for the lib.

I'm using it, but I've found an issue: using MYSQL, touch method isn't working. The broken code is on line 250:
expired: new Date(sess.cookie.expires).toISOString()

When touching, update expired column, but differently of set method. On set method, using mysql, the value to insert is this (line 200):
new Date(expired).toISOString().slice(0, 19).replace('T', ' ')

which become this date: '2016-02-12 02:04:13'.

On touch method, the value just turn into ISOString like '2016-02-12T01:07:22.999Z'.

Doing that, throws that error: ER_TRUNCATED_WRONG_VALUE: Truncated incorrect datetime value: '2016-02-12T01:07:22.999Z',

This can be fixed just changing expire value, creating an unique method that returns the correct value and using it in touch AND get methods.

nowAsISO

Other point to review is the function nowAsISO, that return the date as the same format that touch ethod uses to update. This method must return the correct value too, because is used on touch and methods.

Should i make a pull request with the fixed code?

Ps.: Sorry for my english

gx0r commented

Thanks for reporting! Feel free to make a pull request. Ideally we would have an automated test for touch for all DB's.