libsql / hrana-client-ts

Hrana client for TypeScript and JavaScript
https://libsql.org/hrana-client-ts/
MIT License
23 stars 7 forks source link

JS not able to represent long integer with Number #3

Closed AkshayBhimani closed 1 year ago

AkshayBhimani commented 1 year ago

When trying to fetch data from Turso DB where one table column has long integer (for me integer with 19 digit ). It is giving error cannot be safely represented as a JavaScript number

Full trace :

RangeError: Received integer 1658936802800002836 which cannot be safely represented as a JavaScript number
    at valueFromProto (/home/user/project/node_modules/@libsql/hrana-client/lib-esm/value.js:46:19)
    at rowFromProto (/home/user/project/node_modules/@libsql/hrana-client/lib-esm/result.js:37:23)
    at /home/user/project/node_modules/@libsql/hrana-client/lib-esm/result.js:13:44
    at Array.map (<anonymous>)
    at rowsResultFromProto (/home/user/project/node_modules/@libsql/hrana-client/lib-esm/result.js:13:33)
    at Object.responseCallback (/home/user/project/node_modules/@libsql/hrana-client/lib-esm/stream.js:41:30)
    at Client.#handleMsg (/home/user/project/node_modules/@libsql/hrana-client/lib-esm/client.js:213:31)
    at Client.#onSocketMessage (/home/user/project/node_modules/@libsql/hrana-client/lib-esm/client.js:178:18)
    at /home/user/project/node_modules/@libsql/hrana-client/lib-esm/client.js:53:66
    at /home/user/project/node_modules/@miniflare/shared/src/event.ts:29:9
TypeError: WebSocket already closed
    at _WebSocket.[kClose] (/home/user/project/node_modules/@miniflare/web-sockets/src/websocket.ts:298:38)
    at _WebSocket.close (/home/user/project/node_modules/@miniflare/web-sockets/src/websocket.ts:291:10)
    at Client.#setClosed (/home/user/project/node_modules/@libsql/hrana-client/lib-esm/client.js:165:22)
    at Client.#onSocketMessage (/home/user/project/node_modules/@libsql/hrana-client/lib-esm/client.js:182:18)
    at /home/user/project/node_modules/@libsql/hrana-client/lib-esm/client.js:53:66
    at /home/user/project/node_modules/@miniflare/shared/src/event.ts:29:9
    at /home/user/project/node_modules/@miniflare/web-sockets/src/websocket.ts:189:38
    at AsyncLocalStorage.run (node:async_hooks:330:14)
honzasp commented 1 year ago

Hi, thank you for your bug report! :) This is related to an existing issue: https://github.com/libsql/libsql-client-ts/issues/32

Basically, this is expected default behavior: we chose to convert SQLite integers to JavaScript numbers by default, but we don't yet provide a way to opt into using bigints instead.

What would be your preferred solution? Would you prefer if we returned integers as bigints by default?

honzasp commented 1 year ago

Fixed in version 0.4.2, you can use Client.intMode or Stream.intMode to choose the JavaScript representation of SQLite integers: either number, bigint or string.