surrealdb / surrealist

Surrealist is the ultimate way to visually manage your SurrealDB database
https://surrealist.app/
MIT License
1.06k stars 82 forks source link

Large numbers being floored #168

Closed UwUDev closed 4 months ago

UwUDev commented 8 months ago

Describe the bug Large numbers (i guess above an u32) get their last decimal floored to 0

Edit: Sometime it can be more than one decimal

To Reproduce Steps to reproduce the behavior:

  1. Create a sample table
  2. put a lage numer such as 574317759736053768
  3. Make a querry that get this value such as select test_column from test_table
  4. You could see that the value will be 574317759736053760 instead of 574317759736053768

Expected behavior Get the right number

Environment (you can view the current version under Settings):

Got: image

You can also see that sometimes the last two decimals got floored

UwUDev commented 7 months ago

The issue seems to come fromJSON.parse() image

Maybe there is a better lib to parse json in TS

EDIT: using bigint seems to fix it

function reviver(key, value) {
  if (typeof value === 'string') {
    if (/^\d+$/.test(value)) {
      return BigInt(value);
    }
  }
  return value;
}

const parsed = JSON.parse(jsonString, reviver);
macjuul commented 7 months ago

This is an extremely tricky issue to solve, as even revivers won't result in the correct outcome (See https://jsoneditoronline.org/indepth/parse/why-does-json-parse-corrupt-large-numbers/).

I'll continue to investigate possible solutions for this issue though.

macjuul commented 4 months ago

This has now been resolved in Surrealist 2.0 when previewing responses in SurrealQL, as unlike JSON, SurrealQL does support 64-bit numbers.

We are still rolling this out to other editors throughout Surrealist in the coming releases