Comments (8)
I don't mind doing a PR based on your suggestions.
from nodejs-idb-pconnector.
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:
-
SQL_NUMERIC
andSQL_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 asNumbers
(or rather numbers), should be coerced. The problem is, the way you do it, by calling JavaScript'sNumber()
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... -
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
andDOUBLE
(can fit in Number I believe),DECFLOAT
(not sure the max size, will have to look into it). -
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. -
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 likejsonifyData
? I don't know, will have to brainstorm on it.
Thanks for working to make the connector better!
from nodejs-idb-pconnector.
from nodejs-idb-pconnector.
@2upmedia
Currently there is a way to return numeric data as a JS Number
instead of a JS String
by 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.
Does #55 solve this?
from nodejs-idb-pconnector.
from nodejs-idb-pconnector.
#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.
👋 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)
- setLibraryList and sql user defined functions HOT 5
- dbpool failed to detach HOT 19
- Run linter during PR HOT 1
- Fix eslint errors
- Max number of simultaneous connections HOT 8
- Drop standard-version as its now deprecated HOT 2
- Calling Store Proc passing well IN parms , not getting OUT parm HOT 2
- DBPool example is incomplete.. HOT 1
- Please make more clear how to call a Stored Procedure HOT 7
- No clear explanation on how to call stored procedure. Not receiving output.
- More examples HOT 5
- bindParam() is deprecated and you should use bindParameters() instead HOT 8
- Fix copyright headers on source files
- Add package-lock.json HOT 1
- DBPool 'new connection' event emitter issues HOT 1
- build: Add standard-version HOT 1
- Migrate docs to readthedocs HOT 1
- Add exempt-pr-label
- DBPool.prepareExecute should provide a way to enable numeric type conversion HOT 7
- fetchAll keys lower case HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodejs-idb-pconnector.