module Sequel::Postgres::PGRange::DatabaseMethods

  1. lib/sequel/extensions/pg_range.rb
Parent: PGRange

Methods

Public Class

  1. define_range_typecast_method
  2. extended

Public Instance

  1. bound_variable_arg

Public Class methods

define_range_typecast_method (type, parser)

Define a private range typecasting method for the given type that uses the parser argument to do the type conversion.

[show source]
# File lib/sequel/extensions/pg_range.rb, line 208
def self.define_range_typecast_method(type, parser)
  meth = :"typecast_value_#{type}"
  define_method(meth){|v| typecast_value_pg_range(v, parser)}
  private meth
end
extended (db)

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

[show source]
# File lib/sequel/extensions/pg_range.rb, line 187
def self.extended(db)
  db.instance_eval do
    extend_datasets(DatasetMethods)
    copy_conversion_procs([3904, 3906, 3912, 3926, 3905, 3907, 3913, 3927])
    [:int4range, :numrange, :tsrange, :tstzrange, :daterange, :int8range].each do |v|
      @schema_type_classes[v] = PGRange
    end
  end

  procs = db.conversion_procs
  procs[3908] = Parser.new("tsrange", procs[1114])
  procs[3910] = Parser.new("tstzrange", procs[1184])
  if defined?(PGArray::Creator)
    procs[3909] = PGArray::Creator.new("tsrange", procs[3908])
    procs[3911] = PGArray::Creator.new("tstzrange", procs[3910])
  end

end

Public Instance methods

bound_variable_arg (arg, conn)

Handle Range and PGRange values in bound variables

[show source]
# File lib/sequel/extensions/pg_range.rb, line 215
def bound_variable_arg(arg, conn)
  case arg
  when PGRange 
    arg.unquoted_literal(schema_utility_dataset)
  when Range
    PGRange.from_range(arg).unquoted_literal(schema_utility_dataset)
  else
    super
  end
end