| Module | Sequel::Postgres::PGRange::DatabaseMethods |
| In: |
lib/sequel/extensions/pg_range.rb
|
Define a private range typecasting method for the given type that uses the parser argument to do the type conversion.
# File lib/sequel/extensions/pg_range.rb, line 208
208: def self.define_range_typecast_method(type, parser)
209: meth = "typecast_value_#{type}""typecast_value_#{type}"
210: define_method(meth){|v| typecast_value_pg_range(v, parser)}
211: private meth
212: end
Reset the conversion procs if using the native postgres adapter, and extend the datasets to correctly literalize ruby Range values.
# File lib/sequel/extensions/pg_range.rb, line 187
187: def self.extended(db)
188: db.instance_eval do
189: extend_datasets(DatasetMethods)
190: copy_conversion_procs([3904, 3906, 3912, 3926, 3905, 3907, 3913, 3927])
191: [:int4range, :numrange, :tsrange, :tstzrange, :daterange, :int8range].each do |v|
192: @schema_type_classes[v] = PGRange
193: end
194: end
195:
196: procs = db.conversion_procs
197: procs[3908] = Parser.new("tsrange", procs[1114])
198: procs[3910] = Parser.new("tstzrange", procs[1184])
199: if defined?(PGArray::Creator)
200: procs[3909] = PGArray::Creator.new("tsrange", procs[3908])
201: procs[3911] = PGArray::Creator.new("tstzrange", procs[3910])
202: end
203:
204: end
Handle Range and PGRange values in bound variables
# File lib/sequel/extensions/pg_range.rb, line 215
215: def bound_variable_arg(arg, conn)
216: case arg
217: when PGRange
218: arg.unquoted_literal(schema_utility_dataset)
219: when Range
220: PGRange.from_range(arg).unquoted_literal(schema_utility_dataset)
221: else
222: super
223: end
224: end