cornucopia-rs / cornucopia

Generate type-checked Rust from your PostgreSQL.
Other
755 stars 31 forks source link

Switch rust_decimal to BigDecimal, and increase precision to match Postgres NUMERIC type precision #206

Closed farazfazli closed 1 year ago

farazfazli commented 1 year ago

Addresses #204, WIP. Currently, facing an error due to BigDecimal not implementing the FromSql<'a> trait.

farazfazli commented 1 year ago

@xoac @LouisGariepy Any ideas on how to fix this? Looks like due to language design, I can't add an additional trait to an external type.

LouisGariepy commented 1 year ago

@farazfazli That's right. To implement a trait, you must either own the type or the trait. This is called "orphan rules".

That's why the solution Xoac mentioned in the original issue included

add PR for bigdecimal crate to optionally enable support for postgresql?

They have to add the implementation upstream.

farazfazli commented 1 year ago

@LouisGariepy Makes sense, thanks for explaining. I will look into what's needed to open a PR upstream.

farazfazli commented 1 year ago

Looks like the BigDecimal crate is hardly maintained, and rust_decimal has a hard limit of 28 digits for precision: https://github.com/paupino/rust-decimal/issues/562

farazfazli commented 1 year ago

Closing this PR for now, we can create a new one if a crate is found which satisfies our requirements.