sidorares / sidorares/node-mysql2

Inserting date

Open
#712 12 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

There must be something on my side but I am somewhat stuck.

I'm inserting data into a table using the following approach:

const p = await getPool(name); // caching the pool because I'm accessing multiple dbs
const insertFbl = 'INSERT INTO fbl SET ?'
const result = p.query(insertFbl, some_object)

some_object has some date fields.

When I run the query I get an error like this (for the sake of testing I did init my date field with new Date()):

Incorrect datetime value: '2018-01-21T00:37:07.837Z' for column 'feedback_date' at row 1
at PromisePool.query (/server/node_modules/mysql2/promise.js:344:20)
...

On the other hand, if I use some string like moment(somedate).format('YYYY-MM-DDThh:mm:ss'), it will insert without any problem.

That's weird because not only mysql2 is supposed to make the appropriate conversion and moreover I could swear I had already used javascript date variables before.

Any idea?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the PromisePool.query path mentioned in /server/node_modules/mysql2/promise.js:344:20 and reproduce the INSERT INTO fbl SET ? call with some_object containing new Date() values. Compare that result with the moment(...).format(...) string case; done means establishing the supported date input and conversion behavior, with a reproducible test or documented conclusion.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mysql, node.js
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.