Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs teradata returns "nodeJava_java_math_BigDecimal{}" instead of decimal value in the resultset?

i am running a simple select query. the code runs fine and its returning the resultset as well showing all the column values which are in character format but showing "nodeJava_java_math_BigDecimal{}" insted of decimal format columns ?

var Teradata = require('node-teradata');  


var config = { 
url: 'jdbc:teradata://abc.com/database=abab', 
 username: '****',   
  password: '****',  
  driver: './jars/',  
  minPoolSize: 1,
    maxPoolSize: 100,   
    keepalive: {   
      interval: 60000,   
      query: 'SELECT 1',   
      enabled: true   
    }     
};   

var teradata = new Teradata(config);

var sql = "select name,QTY from products where id='700018'";

return teradata.read(sql)
  .then(function(response) {
    console.log(response);
  });

the result its printing on console is:

[{name:'Apple Juice',QTY:nodeJava_java_math_BigDecimal{}}]
like image 811
Navjot Singh Saund Avatar asked Dec 02 '25 06:12

Navjot Singh Saund


1 Answers

You can retype the properties of the returned object with the JavaScript types you know you'll be working with, using methods like Number([...]) or .toString()

return teradata.read(sql)
    .then(function(response) {
        return response.map(respObj => objExtractor(respObj));
});

function objExtractor(teradataObj) {
    return {
        name: teradataObj.name.toString(),
        QTY: Number(teradataObj.QTY).toFixed(0)
    }
}
like image 158
MdE Avatar answered Dec 03 '25 19:12

MdE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!