From 1fe0c5f616923a8107d7db257eff2729c4425c06 Mon Sep 17 00:00:00 2001 From: kevinhikaruevans Date: Mon, 21 Jul 2014 11:02:11 -0700 Subject: [PATCH 1/2] support for POINT class --- lib/protocol/SqlString.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/protocol/SqlString.js b/lib/protocol/SqlString.js index c9883daa3..ba63a1dbb 100644 --- a/lib/protocol/SqlString.js +++ b/lib/protocol/SqlString.js @@ -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')) { + return 'POINT(' + [val.x, val.y].map(parseFloat).join(',') + ')'; + } if (stringifyObjects) { val = val.toString(); } else { From 74a175423c0742d7a1d927ab57b9f44aef8ca6d8 Mon Sep 17 00:00:00 2001 From: kevinhikaruevans Date: Mon, 21 Jul 2014 11:28:54 -0700 Subject: [PATCH 2/2] unit test for point --- test/unit/protocol/test-SqlString.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/unit/protocol/test-SqlString.js b/test/unit/protocol/test-SqlString.js index dffede32f..9e6973dcd 100644 --- a/test/unit/protocol/test-SqlString.js +++ b/test/unit/protocol/test-SqlString.js @@ -117,7 +117,13 @@ test('SqlString.escape', { assert.strictEqual(string, "'" + expected + "'"); }, - + 'points are converted to POINT objects': function() { + var expected = 'POINT(123.004, -10.1)'; + var input = {x: 123.004, y: -10.1}; + var string = SqlString.escape(input); + + assert.strictEqual(string, expected); + }, 'buffers are converted to hex': function() { var buffer = new Buffer([0, 1, 254, 255]); var string = SqlString.escape(buffer);