When using knex in a node application is there any way to set a MySQL datetime column as datetime(3) or datetime(6), or better yet set a default for all datetime columns including .timestamps?
Right now it looks like I'm getting the milliseconds truncated when I insert into the DB and then retrieve.
Thanks!
After asking about this exact situation on the knex gitter channel, I was pointed to the .specificType()
function for handling this specific situation. So (in mysql, for example):
table.specificType('createdAt', 'DATETIME(6)');
would create a DATETIME
column named createdAt
with fractional seconds of up to 6 precision. I will update this answer to confirm once I have had a chance to test with my local code.
UPDATE: This does indeed work as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With