rom-sql icon indicating copy to clipboard operation
rom-sql copied to clipboard

PG range insertion does not work with rom 5.1.1

Open cutalion opened this issue 6 years ago • 0 comments

Creating record in table with pg range column does not work.

Example: https://github.com/cutalion/rom_experiments/blob/fdae88c28d7f5b59ccf9a40de8a4fc0916b9c2c5/pg_range.rb

def try(name)
  yield
  puts "#{name} works"
  rescue => e
    puts "#{name} does not work"
    puts e.message
  ensure
    puts
end


ruby_range = Range.new(Time.now, Time.now)
rom_range = ROM::SQL::Postgres::Values::Range.new(Time.now, Time.now)
sequel_range = Sequel::Postgres::PGRange.new(Time.now, Time.now)
custom_range = CustomRange.new(Time.now, Time.now)

try(:ruby_range) { pg_ranges.changeset(:create, range: ruby_range).commit }
try(:sequel_range) { pg_ranges.changeset(:create, range: sequel_range).commit }
try(:rom_range) { pg_ranges.changeset(:create, range: rom_range).commit }
try(:custom_range) { pg_ranges.changeset(:create, range: custom_range).commit }

Output:

$ bundle exec ruby pg_range.rb
ruby_range does not work
2019-08-15 19:37:25 +0300..2019-08-15 19:37:25 +0300 (Range) has invalid type for :range violates constraints (undefined method `exclude_begin?' for 2019-08-15 19:37:25 +0300..2019-08-15 19:37:25 +0300:Range
Did you mean?  exclude_end? failed)

sequel_range does not work
#<Sequel::Postgres::PGRange:0x000055f59c094448 @begin=2019-08-15 19:37:25 +0300, @end=2019-08-15 19:37:25 +0300, @empty=false, @exclude_begin=false, @exclude_end=false, @db_type=nil> (Sequel::Postgres::PGRange) has invalid type for :range violates constraints (undefined method `lower' for #<Sequel::Postgres::PGRange:0x000055f59c094448> failed)

rom_range does not work
"[2019-08-15 19:37:25 +0300,2019-08-15 19:37:25 +0300)" (String) has invalid type for :range violates constraints (undefined method `exclude_begin?' for "[2019-08-15 19:37:25 +0300,2019-08-15 19:37:25 +0300)":String failed)

custom_range does not work
"[2019-08-15 19:37:25 +0300,2019-08-15 19:37:25 +0300]" (String) has invalid type for :range violates constraints (undefined method `exclude_begin?' for "[2019-08-15 19:37:25 +0300,2019-08-15 19:37:25 +0300]":String failed)

This issue may be related to #286 (ruby ranges not working), but with latest rom/dry updates even ROM::SQL::Postgres::Values::Range does not work.

cutalion avatar Aug 15 '19 16:08 cutalion