mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
GNU Lesser General Public License v2.1
366 stars 91 forks source link

Feature request: `checkNumberRange: boolean` #201

Closed urugator closed 2 years ago

urugator commented 2 years ago

BigInt as a safe default is good, but I often find it quite impractical, because mariadb returns BIGINT from various operations like COUNT(*) or col + 1 (note CAST(aBigInt AS INT) still results in BIGINT). At the moment we can either choose to use the default safe behavior, but then we have to check the range and cast these to number manually or we can use bigIntAsNumber: true for convinience, but risk an invalid behavior in edge cases. I propose introducing a new option, which would provide conviniency, but would fail loudly in case of possible error: checkNumberRange: boolean When set to true, the driver throws an error if DECIMAL/BIGINT can't be converted safely to number. The option is only effective when one of insertIdAsNumber/decimalAsNumber/bigIntAsNumber is true. Defaults to false for BC reasons.

rusher commented 2 years ago

Right, i think that can be a nice addition to and a very practical option. I've create https://jira.mariadb.org/browse/CONJS-198 for that. This will be part of next release.

rusher commented 2 years ago

closing, since done in develop branch and will be part of 3.0.1

urugator commented 2 years ago

Thank you for the feature! I think you forget to add the new option to types: https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/master/types/index.d.ts Should I open new issue?