onyxframework / sql

A delightful SQL ORM ☺️
https://api.onyxframework.com/sql
MIT License
91 stars 7 forks source link

PG::Numeric converter #104

Closed Blacksmoke16 closed 2 years ago

Blacksmoke16 commented 5 years ago

Currently when using a float column type other than REAL/DOUBLE PRECISION, it will throw a PG::ResultSet#read returned a PG::Numeric. A (Float64 | Nil) was expected

  class Character
    include Onyx::SQL::Model

    schema characters do
      pkey id : Int32
      type balance : Float64, not_null: true # => DECIMAL(16, 2)
    end
  end

Prob just need to add a converter to convert PG::Numeric type into the desired numeric type.

vladfaust commented 5 years ago

You could either use FLOAT8 type in PG or use PG::Numeric converter (if it doesn't work out of the box, try creating one, looking at PG::Enum for inspiration.

Blacksmoke16 commented 5 years ago

I was originally using FLOAT8, but need DECIMAL for the precision. But yea, I ended up just defining my own converter. Is that something you would want built in tho?

vladfaust commented 5 years ago

I think that it wouldn't be bad to have such a converter by default...