Module Sequel::Postgres::IntervalDatabaseMethods
In: lib/sequel/extensions/pg_interval.rb

Methods

Classes and Modules

Class Sequel::Postgres::IntervalDatabaseMethods::Parser

Constants

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).

Public Class methods

Reset the conversion procs if using the native postgres adapter, and extend the datasets to correctly literalize ActiveSupport::Duration values.

[Source]

     # 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.

[Source]

    # 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

Public Instance methods

Handle ActiveSupport::Duration values in bound variables

[Source]

     # File lib/sequel/extensions/pg_interval.rb, line 126
126:       def bound_variable_arg(arg, conn)
127:         case arg
128:         when ActiveSupport::Duration
129:           IntervalDatabaseMethods.literal_duration(arg)
130:         else
131:           super
132:         end
133:       end

[Validate]