module Sequel::Postgres::IntervalDatabaseMethods
Constants
- DURATION_UNITS
- PARSER
Single instance of
Parser
used for parsing, to save on memory (since the parser has no state).
Public Class Methods
extended(db)
click to toggle source
Reset the conversion procs if using the native postgres adapter, and extend the datasets to correctly literalize ActiveSupport::Duration values.
# File lib/sequel/extensions/pg_interval.rb 143 def self.extended(db) 144 db.instance_exec do 145 extend_datasets(IntervalDatasetMethods) 146 add_conversion_proc(1186, Postgres::IntervalDatabaseMethods::PARSER) 147 if respond_to?(:register_array_type) 148 register_array_type('interval', :oid=>1187, :scalar_oid=>1186) 149 end 150 @schema_type_classes[:interval] = ActiveSupport::Duration 151 end 152 end
literal_duration(duration)
click to toggle source
Return an unquoted string version of the duration object suitable for use as a bound variable.
# File lib/sequel/extensions/pg_interval.rb 52 def self.literal_duration(duration) 53 h = Hash.new(0) 54 duration.parts.each{|unit, value| h[unit] += value} 55 s = String.new 56 57 DURATION_UNITS.each do |unit| 58 if (v = h[unit]) != 0 59 s << "#{v.is_a?(Integer) ? v : sprintf('%0.6f', v)} #{unit} " 60 end 61 end 62 63 if s.empty? 64 '0' 65 else 66 s 67 end 68 end
Public Instance Methods
bound_variable_arg(arg, conn)
click to toggle source
Handle ActiveSupport::Duration values in bound variables.
Calls superclass method
# File lib/sequel/extensions/pg_interval.rb 155 def bound_variable_arg(arg, conn) 156 case arg 157 when ActiveSupport::Duration 158 IntervalDatabaseMethods.literal_duration(arg) 159 else 160 super 161 end 162 end