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 124
124:       def self.extended(db)
125:         db.instance_eval do
126:           extend_datasets(IntervalDatasetMethods)
127:           copy_conversion_procs([1186, 1187])
128:           @schema_type_classes[:interval] = ActiveSupport::Duration
129:         end
130:       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 49
49:       def self.literal_duration(duration)
50:         h = Hash.new(0)
51:         duration.parts.each{|unit, value| h[unit] += value}
52:         s = ''
53: 
54:         DURATION_UNITS.each do |unit|
55:           if (v = h[unit]) != 0
56:             s << "#{v.is_a?(Integer) ? v : sprintf('%0.6f', v)} #{unit} "
57:           end
58:         end
59: 
60:         if s.empty?
61:           EMPTY_INTERVAL
62:         else
63:           s
64:         end
65:       end

Public Instance methods

Handle ActiveSupport::Duration values in bound variables.

[Source]

     # File lib/sequel/extensions/pg_interval.rb, line 133
133:       def bound_variable_arg(arg, conn)
134:         case arg
135:         when ActiveSupport::Duration
136:           IntervalDatabaseMethods.literal_duration(arg)
137:         else
138:           super
139:         end
140:       end

[Validate]