Module | Sequel::Postgres::IntervalDatabaseMethods |
In: |
lib/sequel/extensions/pg_interval.rb
|
EMPTY_INTERVAL | = | '0'.freeze | ||
DURATION_UNITS | = | [:years, :months, :days, :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 121 121: def self.extended(db) 122: db.extend_datasets(IntervalDatasetMethods) 123: 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 46 46: def self.literal_duration(duration) 47: h = Hash.new(0) 48: duration.parts.each{|unit, value| h[unit] += value} 49: s = '' 50: 51: DURATION_UNITS.each do |unit| 52: if (v = h[unit]) != 0 53: s << "#{v.is_a?(Integer) ? v : sprintf('%0.6f', v)} #{unit} " 54: end 55: end 56: 57: if s.empty? 58: EMPTY_INTERVAL 59: else 60: s 61: end 62: end