From a5ee3651162e7dd176b0c6d0d0f76f2984c6ca44 Mon Sep 17 00:00:00 2001 From: brianc Date: Thu, 7 Mar 2013 16:19:11 -0600 Subject: [PATCH] remove parseFloat --- lib/types/textParsers.js | 30 +------------------ .../integration/client/type-coercion-tests.js | 9 +++--- test/unit/client/typed-query-results-tests.js | 6 ++-- 3 files changed, 8 insertions(+), 37 deletions(-) diff --git a/lib/types/textParsers.js b/lib/types/textParsers.js index 77d2a48..c7525e8 100644 --- a/lib/types/textParsers.js +++ b/lib/types/textParsers.js @@ -78,18 +78,8 @@ var parseIntegerArray = function(val) { }; var parseFloatArray = function(val) { - deprecate('parsing and returning floats from PostgreSQL server is deprecated', - 'JavaScript has a hard time with floats and there is precision loss which can cause', - 'unexpected, hard to trace, potentially bad bugs in your program', - 'for more information see the following:', - 'https://github.com/brianc/node-postgres/pull/271', - 'in node-postgres v1.0.0 all floats & decimals will be returned as strings', - 'feel free to get in touch via a github issue if you have any questions'); if(!val) { return null; } - var p = arrayParser.create(val, function(entry){ - if(entry !== null) { - entry = parseFloat(entry, 10); - } + var p = arrayParser.create(val, function(entry) { return entry; }); @@ -171,27 +161,11 @@ var parseInteger = function(val) { return parseInt(val, 10); }; -var parseFloatAndWarn = function(val) { - deprecate('parsing and returning floats from PostgreSQL server is deprecated', - 'JavaScript has a hard time with floats and there is precision loss which can cause', - 'unexpected, hard to trace, potentially bad bugs in your program', - 'for more information see the following:', - 'https://github.com/brianc/node-postgres/pull/271', - 'in node-postgres v1.0.0 all floats & decimals will be returned as strings'); - return parseFloat(val); -}; - var init = function(register) { register(20, parseInteger); register(21, parseInteger); register(23, parseInteger); register(26, parseInteger); - //TODO remove for v1.0 - register(1700, parseFloatAndWarn); - //TODO remove for v1.0 - register(700, parseFloatAndWarn); - //TODO remove for v1.0 - register(701, parseFloatAndWarn); register(16, parseBool); register(1082, parseDate); // date register(1114, parseDate); // timestamp without timezone @@ -199,8 +173,6 @@ var init = function(register) { register(1005, parseIntegerArray); // _int2 register(1007, parseIntegerArray); // _int4 register(1016, parseIntegerArray); // _int8 - register(1021, parseFloatArray); // _float4 - register(1022, parseFloatArray); // _float8 register(1231, parseIntegerArray); // _numeric register(1014, parseStringArray); //char register(1015, parseStringArray); //varchar diff --git a/test/integration/client/type-coercion-tests.js b/test/integration/client/type-coercion-tests.js index 9e67558..61204cf 100644 --- a/test/integration/client/type-coercion-tests.js +++ b/test/integration/client/type-coercion-tests.js @@ -57,15 +57,14 @@ var types = [{ name: 'bool', values: [true, false, null] },{ - //TODO get some actual huge numbers here name: 'numeric', - values: [-12.34, 0, 12.34, null] + values: ['-12.34', '0', '12.34', null] },{ name: 'real', - values: [101.1, 0, -101.3, null] + values: ['101.1', '0', '-101.3', null] },{ name: 'double precision', - values: [-1.2, 0, 1.2, null] + values: ['-1.2', '0', '1.2', null] },{ name: 'timestamptz', values: [null] @@ -83,7 +82,7 @@ var types = [{ // ignore some tests in binary mode if (helper.config.binary) { types = types.filter(function(type) { - return !(type.name in {'real':1, 'timetz':1, 'time':1}); + return !(type.name in {'real':1, 'timetz':1, 'time':1, 'numeric': 1, 'double precision': 1}); }); } diff --git a/test/unit/client/typed-query-results-tests.js b/test/unit/client/typed-query-results-tests.js index 5520245..eda34fb 100644 --- a/test/unit/client/typed-query-results-tests.js +++ b/test/unit/client/typed-query-results-tests.js @@ -43,19 +43,19 @@ test('typed results', function() { format: 'text', dataTypeID: 1700, actual: '12.34', - expected: 12.34 + expected: '12.34' },{ name: 'real/float4', dataTypeID: 700, format: 'text', actual: '123.456', - expected: 123.456 + expected: '123.456' },{ name: 'double precision / float8', format: 'text', dataTypeID: 701, actual: '1.2', - expected: 1.2 + expected: '1.2' },{ name: 'boolean true', format: 'text',