-
Notifications
You must be signed in to change notification settings - Fork 2.5k
support for POINT class #877
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
Conversation
It needs tests, if you are so inclined :) |
Added a test for it! Not sure how many tests are required. There probably should be a separate function for geometry in SqlString, like |
That's fine, I just wanted a test so I know what you were expecting to happen. So I see form the test, it has the issue I described, where before your change that objects would have resulted in For example, this use-case needs to continue to work with your change: connection.query('INSERT INTO data SET ?', {x: 3, y: 7}) where there is an |
Oh, I intended it for it to be objects within objects. I didn't know |
OK, as long as that is your intention. I can adjust your PR then later :) |
17209da
to
76de66e
Compare
@@ -36,6 +36,10 @@ SqlString.escape = function(val, stringifyObjects, timeZone) { | |||
} | |||
|
|||
if (typeof val === 'object') { | |||
// for the mysql point class | |||
if(val.hasOwnProperty('x') && val.hasOwnProperty('y')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also make this a little less risky by saying "if it has x and y and no other properties"
5847ec8
to
be37e88
Compare
65c4c0c
to
fa96a75
Compare
Since node-mysql supports SELECTing and casting the POINT class, it would make sense to also support escaping
POINT
s during INSERTs and UPDATEs. Currently, if you SELECT a field with a point, it'll return a plain object withx
andy
attributes. This PR will allow it to also INSERT and UPDATE an object withx
andy
attributes.I have no idea if this was the correct way to append a new type in
SqlString
, but it works fine for me. Date casts were defined there, so it seemed like a good place to start. The POINT function is defined here.