Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with isInstance #241

Open
hdoan741 opened this issue Oct 9, 2023 · 2 comments
Open

Issue with isInstance #241

hdoan741 opened this issue Oct 9, 2023 · 2 comments

Comments

@hdoan741
Copy link

hdoan741 commented Oct 9, 2023

I'm receiving a BigInteger value from snowflake-sdk & I need to convert it to JS Number or JS Big Int to serialize it correctly. When I try to use bigInt.isInstance(value), it always return false. Can you help me understand what's wrong?

// rows = snowflakeConn.execute({binds, sqlText})
// rows contains some BigInteger value 
// cellValue extracted from rows

import bigInt from 'big-integer'
bigInt.isInstance(cellValue) # false

# { cellValue: Integer { value: 159100n }, isBigInt: false }
# { cellValue: Integer { value: 159200n }, isBigInt: false }

I've also tried the following import & it didn't work either/

import * as bigInt from 'big-integer'

As far as I know, they creates bigInt value like this:
https://github.com/snowflakedb/snowflake-connector-nodejs/blob/21f884c0a050f536fb1a87ddcc28cacaaeb71daf/lib/connection/result/column.js#L303

Currently, I'm using a workaround like this:

  return typeof value === 'object' && value.constructor.name === 'Integer'

On a separate note, It would also be useful to have a toJSValue() that return the underlying value in JS type. toJSNumber is useful but it only works correctly for non-big-int numbers.

@peterolson
Copy link
Owner

Can you create a reproducible example of this issue? It's not clear to me where value is coming from.

@ZLY201
Copy link

ZLY201 commented May 6, 2024

Please make sure the bigInt class you used is the same class because the isInstance function use instanceof to check.

The situation may be like this:

- node_modules
-- A
---- big-int
- big-int

So you import two different bigint class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants