Module: Torque::PostgreSQL::Relation::JoinSeries
- Defined in:
- lib/torque/postgresql/relation/join_series.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#join_series(range, **xargs, &block) ⇒ Object
Creates a new join based on PG generate_series() function.
-
#join_series!(range, **xargs, &block) ⇒ Object
Like #join_series, but modifies relation in place.
Class Method Details
.build(relation, range, with: nil, as: :series, step: nil, time_zone: nil, mode: :inner, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/torque/postgresql/relation/join_series.rb', line 10 def build(relation, range, with: nil, as: :series, step: nil, time_zone: nil, mode: :inner, &block) validate_build!(range, step) args = [bind_value(range.begin), bind_value(range.end)] args << bind_value(step) if step args << bind_value(time_zone) if time_zone result = Arel::Nodes::Ref.new(as.to_s) func = FN.generate_series(*args).as(as.to_s) condition = build_join_on(result, relation, with, &block) arel_join(mode).new(func, func.create_on(condition)) end |
Instance Method Details
#join_series(range, **xargs, &block) ⇒ Object
Creates a new join based on PG generate_series() function. It is based on ranges, supports numbers and dates (as per PG documentation), custom stepping, time zones, and more. This simply coordinates the initialization of the the proper join
99 100 101 |
# File 'lib/torque/postgresql/relation/join_series.rb', line 99 def join_series(range, **xargs, &block) spawn.join_series!(range, **xargs, &block) end |
#join_series!(range, **xargs, &block) ⇒ Object
Like #join_series, but modifies relation in place.
104 105 106 107 |
# File 'lib/torque/postgresql/relation/join_series.rb', line 104 def join_series!(range, **xargs, &block) self.joins_values |= [JoinSeries.build(self, range, **xargs, &block)] self end |