Giter Club home page Giter Club logo

Comments (8)

jorgecolonconsulting avatar jorgecolonconsulting commented on August 16, 2024

I don't mind doing a PR based on your suggestions.

from nodejs-idb-pconnector.

markdirish avatar markdirish commented on August 16, 2024

So looking at the fetchColData function in idb-connector (the package that actually does the heavy lifting here), it looks like it should coerce SQL_SMALLINT, SQL_INTEGER, SQL_DECIMAL, and SQL_NUMERIC to be JavaScript Numbers. Does it not coerce those for you, or are you trying to get different types back?

There are several issues here:

  1. SQL_NUMERIC and SQL_DECIMAL can be larger than a JavaScript number can store, so in those cases they should be returned as Strings, and then if stored in JSON as Numbers (or rather numbers), should be coerced. The problem is, the way you do it, by calling JavaScript's Number() function, they can potentially lose data if too big or too small. The better solution is to just enter it into JSON as a string, and then remove the quotes around it. Of course, if JavaScript is going to process that JSON string, you won't be able to just plop that value back into a Number variable, since again it might not be big enough for the data. Hmm...

  2. We really need to support more data types. Off the top of my head, I can think of BIGINT (can fit in JavaScript's new BigInt class), REAL and DOUBLE (can fit in Number I believe), DECFLOAT (not sure the max size, will have to look into it).

  3. I don't think the whole numFields / fetch / fetchAll workflow is that great, but that's more my beef with the connector than with your issue. There are a lot of awaits in your code that will slow down the execution of this function (but not of Node.js, just will increase the time to process this function), but its all data that could have been returned when the query was ran.

  4. If you want to implement it I would be fine with it, we just have to figure where it will go and what it will be called. Instead of coerceDb2Type, something like jsonifyData? I don't know, will have to brainstorm on it.

Thanks for working to make the connector better!

from nodejs-idb-pconnector.

jorgecolonconsulting avatar jorgecolonconsulting commented on August 16, 2024

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on August 16, 2024

@2upmedia

Currently there is a way to return numeric data as a JS Numberinstead of a JS Stringby using dbstmt.asNumber.

Please see this issue.

We may just need to add a wrapper for dbstmt.asNumber in statement.js

from nodejs-idb-pconnector.

kadler avatar kadler commented on August 16, 2024

Does #55 solve this?

from nodejs-idb-pconnector.

jorgecolonconsulting avatar jorgecolonconsulting commented on August 16, 2024

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on August 16, 2024

#55 adds a wrapper for dbstmt.asNumber()

When enabled this will return SMALLINT, INTEGER, DECIMAL, NUMERIC sql types as JavaScript Number rather than the default String.

See https://github.com/IBM/nodejs-idb-connector/blob/master/src/db2ia/dbstmt.cc#L2260

I think returning JavaScript Number for the other types listed here:

SQL_FLOAT:
SQL_REAL:
SQL_DOUBLE:
SQL_DECFLOAT:

Would be better off implemented within idb-connector

The following types are returned as a JavaScript Buffer object

 SQL_VARBINARY:
 SQL_BINARY:
 SQL_BLOB:

All other types are already returned as JavaScript Strings.

from nodejs-idb-pconnector.

github-actions avatar github-actions commented on August 16, 2024

👋 Hi! This issue has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

from nodejs-idb-pconnector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.