Module Sequel::Postgres::PGRange::DatabaseMethods
In: lib/sequel/extensions/pg_range.rb

Methods

Public Class methods

Reset the conversion procs if using the native postgres adapter, and extend the datasets to correctly literalize ruby Range values.

[Source]

     # File lib/sequel/extensions/pg_range.rb, line 240
240:         def self.extended(db)
241:           db.instance_eval do
242:             @pg_range_schema_types ||= {}
243:             extend_datasets(DatasetMethods)
244:             copy_conversion_procs([3904, 3906, 3912, 3926, 3905, 3907, 3913, 3927])
245:             [:int4range, :numrange, :tsrange, :tstzrange, :daterange, :int8range].each do |v|
246:               @schema_type_classes[v] = PGRange
247:             end
248:           end
249: 
250:           procs = db.conversion_procs
251:           procs[3908] = Parser.new("tsrange", procs[1114])
252:           procs[3910] = Parser.new("tstzrange", procs[1184])
253:           if defined?(PGArray::Creator)
254:             procs[3909] = PGArray::Creator.new("tsrange", procs[3908])
255:             procs[3911] = PGArray::Creator.new("tstzrange", procs[3910])
256:           end
257: 
258:         end

Public Instance methods

Handle Range and PGRange values in bound variables

[Source]

     # File lib/sequel/extensions/pg_range.rb, line 261
261:         def bound_variable_arg(arg, conn)
262:           case arg
263:           when PGRange 
264:             arg.unquoted_literal(schema_utility_dataset)
265:           when Range
266:             PGRange.from_range(arg).unquoted_literal(schema_utility_dataset)
267:           else
268:             super
269:           end
270:         end

Register a database specific range type. This can be used to support different range types per Database. Use of this method does not affect global state, unlike PGRange.register. See PGRange.register for possible options.

[Source]

     # File lib/sequel/extensions/pg_range.rb, line 276
276:         def register_range_type(db_type, opts=OPTS, &block)
277:           opts = {:type_procs=>conversion_procs, :typecast_method_map=>@pg_range_schema_types, :typecast_methods_module=>(class << self; self; end)}.merge!(opts)
278:           unless (opts.has_key?(:subtype_oid) || block) && opts.has_key?(:oid)
279:             range_oid, subtype_oid = from(:pg_range).join(:pg_type, :oid=>:rngtypid).where(:typname=>db_type.to_s).get([:rngtypid, :rngsubtype])
280:             opts[:subtype_oid] = subtype_oid unless opts.has_key?(:subtype_oid) || block
281:             opts[:oid] = range_oid unless opts.has_key?(:oid)
282:           end
283: 
284:           PGRange.register(db_type, opts, &block)
285:           @schema_type_classes["#{opts[:type_symbol] || db_type}""#{opts[:type_symbol] || db_type}"] = PGRange
286:           conversion_procs_updated
287:         end

[Validate]