| Module | Sequel::Postgres::IntervalDatabaseMethods |
| In: |
lib/sequel/extensions/pg_interval.rb
|
| DURATION_UNITS | = | [:years, :months, :weeks, :days, :hours, :minutes, :seconds].freeze | ||
| PARSER | = | Parser.new | Single instance of Parser used for parsing, to save on memory (since the parser has no state). |
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, line 116
116: def self.extended(db)
117: db.instance_exec do
118: extend_datasets(IntervalDatasetMethods)
119: add_conversion_proc(1186, Postgres::IntervalDatabaseMethods::PARSER)
120: if respond_to?(:register_array_type)
121: register_array_type('interval', :oid=>1187, :scalar_oid=>1186)
122: end
123: @schema_type_classes[:interval] = ActiveSupport::Duration
124: end
125: end
Return an unquoted string version of the duration object suitable for use as a bound variable.
# File lib/sequel/extensions/pg_interval.rb, line 44
44: def self.literal_duration(duration)
45: h = Hash.new(0)
46: duration.parts.each{|unit, value| h[unit] += value}
47: s = String.new
48:
49: DURATION_UNITS.each do |unit|
50: if (v = h[unit]) != 0
51: s << "#{v.is_a?(Integer) ? v : sprintf('%0.6f', v)} #{unit} "
52: end
53: end
54:
55: if s.empty?
56: '0'
57: else
58: s
59: end
60: end