-
-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use source parameter types #705
Conversation
…g to string (allows round trip of numbers, JSON etc.)
Node 8 build on Travis failed (but passed on AppVeyor). Looks like a random failure with npm. Closing (will reopen to retrigger Travis build). |
Reopening to retrigger Travis build. |
thanks @gazoakley ! I'll try to fix build issue btw date has it's own serialization format, not sure though if there is any benefit over sending them as a string ( you can see how it's serialised in node-mysql2/lib/packets/packet.js Line 230 in 513451f
Haven't started reviewing carefully yet, but you set type for Date to be string, right? |
Hi @sidorares - thanks for a quick response. I didn't spot the date serialization that you suggested although to me I think it'd be preferable for Date objects to round trip back to Date if possible (I don't know if that would be a breaking change?). I'll give it a try. |
not sure I understand. This is client -> mysql communication, not casting results mysql -> js . Prior to your pr all parameters were sent as strings ( and marked as having string type ). On mysql side server would do casting like "prepared statement needs number here, we received "1111" so it's probably a number 1111). |
Sequelize has its own tests that run against drivers, and it expects numbers to round trip with the same type. For example:
Without this PR the tests will fail, since Sequelize sends a number as the input parameter and gets back a string in the result. Granted it's a bit unusual to do this, but the test passes for other drivers (it doesn't currently support bind params for MySQL - sequelize/sequelize#8861 hopes to resolve that) |
oh ok I see now. |
what do you think is ideal behaviour when parameter is undefined? Return error immediately, convert to string "undefined", treat as NULL ? |
…hrow error when passing in undefined parameter
Hi @sidorares In response to your previous post, I'd argue for throwing an error since it doesn't map to a MySQL data type - if you want to provide a parameter as MySQL NULL then use JS null. One thing I struggled with is catching the error properly since I think it's being thrown inside a callback - I had to use I've implemented sending Date objects as DATETIME - other tests are still passing. In response to your follow up, would you like to see an option like |
It looks like the previous behaviour didn't do anything with the timezone either? https://github.com/sidorares/node-mysql2/pull/705/files#diff-3b8f681f01aefd0299dedcf941cd7a3dL46 |
yes, this is how I think about this as well - most
yes, definitely separate pr, just wanted to flag that because it's often cause of a problem for anything related with mysql DATETIME type |
sorry, I'm extremely busy this week, I'll try to find time to help to land this PR |
No worries - thanks for your help so far! 👍 |
Hey @gazoakley sorry for silence.
|
Hi @sidorares - thanks for getting this merged. I've tackled some of the issues identified in #718 |
This PR is a follow on from #353 - it sets the type for bind parameters based on the source parameter type.
DOUBLE
JSON
TINY
There's a PR for sequelize that relies on these changes: sequelize/sequelize#8861