rom-sql: PG range does not work on create

It seems that pg_range extension does not work on inserting records to the database.

rom.relations.pg_ranges.changeset(:create, range: Date.today..(Date.today + 10)).commit
/home/cutalion/.rvm/gems/ruby-2.4.1/gems/rom-sql-2.4.0/lib/rom/sql/extensions/postgres/types/range.rb:80:in `block (2 levels) in range': undefined method `exclude_begin?' for #<Range:0x0000000220da30> (NoMethodError)
Did you mean?  exclude_end?

Full example

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

@culation Thank you for opened issue! I’ll explore it tomorrow in details. Now I see that overlap seems like broken, I would like to fix it.

@cutalion this is a common practice for DB adapters to coerce input data to expected data types. rom-sql usually don’t do anything with your data and relies on the coercion provided by the underlying stack (Sequel + DB adapter). At the same time, we don’t want to expose implementation details by returning Sequel’s wrapper types so we have to provide our own, that’s why we need a custom input type constructor which doesn’t work with ::Range at the moment. This can and should be improved.

However, since PG ranges cannot be represented as ::Range instances in general, we cannot return them. If you’re sure you don’t have such cases where ::Range can’t work you can roll your own type, just in the same way it’s done for ROM::SQL::Postgres::Range. Our best approach is to provide a non-safe to_range converter for ROM::SQL::Postgres::Values::Range