crystal-mysql
crystal-mysql copied to clipboard
Add support for MySql::Type::Decimal
Added support for MySql::Type::Decimal as BigDecimal in crystal.
Thanks for contributing!
I think that the downside of using BigDecimal is that we will force a dependency on libgmp. Not 100% sure. It might also be a bit too much to use BigDecimal for MySQL decimals, but it's like we have a smaller alternative.
Possible outcomes:
- Check/Accept that we will have a libgmp dependency for apps using crystal-mysql. The
decl_type
will cause an entry intypes_by_code
so BigDecimal will always be required even if not used I think. - Put the Decimal support backed with BigDecimal behind a feature flag or an optional
require "mysql/big"
- Create a MySql::Decimal Number type that would be lighter than BigDecimal. This type could offer from/to methods for decimal and other types (at the expense of loosing precision). If the
to_decimal
are not used, then there is no dependency to libgmp.
Let's wait for other's feedback
For my use case, option 3 is probably best. I can imagine there are cases where precision could be more important. It isn't something I run into often.
Yeah, crystal-mysql
should not depend on big
(1). Support for DECIMAL
can be optional (2) or implemented w/o BigDecimal
(3).
I'm fine with either.
(3) Requires some implementation effort, while (2) requires an extra include when you want to use decimals. But both are manageable.