prisma / prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)
Apache License 2.0
1.47k stars 67 forks source link

query bignumber will cause non-recoverable error #603

Closed PaiJi closed 3 years ago

PaiJi commented 4 years ago

if you query a bignumber like 90071992547409910000000000, then prisma direct crash:

Mar 27 18:12:31 VM-167-243-ubuntu: PANIC: Decimal is not a f64. in
Mar 27 18:12:31 VM-167-243-ubuntu: src/libcore/option.rs:1188:5
Mar 27 18:12:31 VM-167-243-ubuntu: This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.

Environment & setup

tomhoule commented 4 years ago

This is out of range for our integer type (64 bit signed integer), and also out of range for double precision floats (without precision loss). This means it cannot be represented at the database level without a proper decimal or bigint representation, which we do not support yet.

I will tag this issue so we can refer to it when we tackle support for a broader set of database types (it's fairly high priority). Thank you for reporting this :)

Quick evcxr debugging session dump:

tom-prisma.tom.~/src/prisma-engine λ evcxr
Welcome to evcxr. For help, type :help
>> extern crate rust_decimal;

>> 
>> let i: u64 = 90071992547409910000000000;
                ^^^^^^^^^^^^^^^^^^^^^^^^^^ 
literal out of range for `u64`
>> use rust_decimal::Decimal;
>> let dec: Decimal = "90071992547409910000000000".parse().unwrap();
>> dec
90071992547409910000000000
>> use rust_decimal::prelude::*;
>> dec
90071992547409910000000000
>> dec.to_f64()
None

>> let f: f64 = 90071992547409910000000000.0;
>> f
90071992547409900000000000.0
>> 
pantharshit00 commented 3 years ago

BigInt is now available in the native types preview: https://www.prisma.io/docs/concepts/components/preview-features/native-types#additional-prisma-types