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.cr

Class Method Summary

Class Method Detail

def self.coerce(value : String, _options) : BigDecimal? #

[View source]
def self.from_db(pull, options) #

[View source]
def self.from_hash(hash : Hash, column, options) #

[View source]
def self.to_db(value : BigDecimal, options) #

[View source]
def self.to_db(value : Nil, options) : Nil #

[View source]