Comments - Unexpected result from mariaDB connector for node in select count

2 years ago Diego Dupin

see https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/master/documentation/promise-api.md#migrating-from-2x-or-mysqlmysql2-to-3x

javascript integer are safe until some limit (2^53). Resultset that return integer since 3.0 return a javascript BigInt (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt). Resultset are now safe.

To permit compatibility, options `insertIdAsNumber`, `decimalAsNumber` and `bigIntAsNumber` can be set to return unsafe value.

It can be done at connection level or query level. Example: const conn = await mariadb.createConnection({ host: 'mydb.com', user: 'myUser', password: 'myPwd', bigIntAsNumber: true, decimalAsNumber: true, bigIntAsNumber: true });

or for a specific query: const res = await conn.query({ sql:'SELECT count(*) as num FROM tasks', bigIntAsNumber: true, decimalAsNumber: true, bigIntAsNumber: true});

for this particular example "SELECT count(*) as num FROM tasks" count would never reach 9007199254740991

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.