|
| 1 | +var deprecate = require('deprecate'); |
| 2 | + |
1 | 3 | var arrayParser = require(__dirname + "/arrayParser.js");
|
2 | 4 |
|
3 | 5 | //parses PostgreSQL server formatted date strings into javascript date objects
|
@@ -76,6 +78,12 @@ var parseIntegerArray = function(val) {
|
76 | 78 | };
|
77 | 79 |
|
78 | 80 | var parseFloatArray = function(val) {
|
| 81 | + deprecate('parsing and returning floats from PostgreSQL server is deprecated', |
| 82 | + 'JavaScript has a hard time with floats and there is precision loss which can cause', |
| 83 | + 'unexpected, hard to trace, potentially bad bugs in your program', |
| 84 | + 'for more information see the following:', |
| 85 | + 'https://github.com/brianc/node-postgres/pull/271', |
| 86 | + 'in node-postgres v1.0.0 all floats & decimals will be returned as strings'); |
79 | 87 | if(!val) { return null; }
|
80 | 88 | var p = arrayParser.create(val, function(entry){
|
81 | 89 | if(entry !== null) {
|
@@ -162,24 +170,27 @@ var parseInteger = function(val) {
|
162 | 170 | return parseInt(val, 10);
|
163 | 171 | };
|
164 | 172 |
|
| 173 | +var parseFloatAndWarn = function(val) { |
| 174 | + deprecate('parsing and returning floats from PostgreSQL server is deprecated', |
| 175 | + 'JavaScript has a hard time with floats and there is precision loss which can cause', |
| 176 | + 'unexpected, hard to trace, potentially bad bugs in your program', |
| 177 | + 'for more information see the following:', |
| 178 | + 'https://github.com/brianc/node-postgres/pull/271', |
| 179 | + 'in node-postgres v1.0.0 all floats & decimals will be returned as strings'); |
| 180 | + return parseFloat(val); |
| 181 | +}; |
| 182 | + |
165 | 183 | var init = function(register) {
|
166 | 184 | register(20, parseInteger);
|
167 | 185 | register(21, parseInteger);
|
168 | 186 | register(23, parseInteger);
|
169 | 187 | register(26, parseInteger);
|
170 | 188 | //TODO remove for v1.0
|
171 |
| - register(1700, function(val){ |
172 |
| - if(val.length > maxLen) { |
173 |
| - console.warn( |
174 |
| - 'WARNING: value %s is longer than max supported numeric value in ' + |
175 |
| - 'javascript. Possible data loss', val); |
176 |
| - } |
177 |
| - return parseFloat(val); |
178 |
| - }); |
| 189 | + register(1700, parseFloatAndWarn); |
179 | 190 | //TODO remove for v1.0
|
180 |
| - register(700, parseFloat); |
| 191 | + register(700, parseFloatAndWarn); |
181 | 192 | //TODO remove for v1.0
|
182 |
| - register(701, parseFloat); |
| 193 | + register(701, parseFloatAndWarn); |
183 | 194 | register(16, parseBool);
|
184 | 195 | register(1082, parseDate); // date
|
185 | 196 | register(1114, parseDate); // timestamp without timezone
|
|
0 commit comments