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.instance_eval do
123:           extend_datasets(IntervalDatasetMethods)
124:           copy_conversion_procs([1186, 1187])
125:           @schema_type_classes[:interval] = ActiveSupport::Duration
126:         end
127:       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 130
130:       def bound_variable_arg(arg, conn)
131:         case arg
132:         when ActiveSupport::Duration
133:           IntervalDatabaseMethods.literal_duration(arg)
134:         else
135:           super
136:         end
137:       end

[Validate]