module Jennifer::Model::BigDecimalConverter(T)
Overview
Type converter for numeric field.
Converts PG::Numeric
(for PostgreSQL) or Float64
data types (for MySQL) field to BigDecimal
and back.
This allows to map numeric fields to BigDecimal
which allows to manipulate float numbers with fixed scale.
It is important to specify scale value - the count of decimal digits in the fractional part, to the right of
the decimal point.
class Order < Jennifer::Model::Base
mapping(
id: Primary32,
# for MySQL use Float64
total: {type: BigDecimal?, converter: Jennifer::Model::BigDecimalConverter(PG::Numeric), scale: 2}
)
end
Defined in:
jennifer/model/big_decimal_converter.crClass Method Summary
- .coerce(value : String, _options) : BigDecimal?
- .from_db(pull, options)
- .from_hash(hash : Hash, column, options)
- .to_db(value : BigDecimal, options)
- .to_db(value : Nil, options) : Nil