Class: Rotulus::ColumnConditionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rotulus/column_condition_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(column, value, direction, tie_breaker_sql = nil) ⇒ ColumnConditionBuilder

Generates a condition builder instance that builds an SQL condition to filter the preceding or succeeding records given a Column instance and its value.

Parameters:

  • column (Rotulus::Column)

    ordered column

  • value (Object)

    the column value for a specific reference record

  • direction (Symbol)

    the seek direction, ‘:next` or `:prev`

  • tie_breaker_sql (Symbol) (defaults to: nil)

    in case :column is not distinct, a ‘tie-breaker’ SQL condition is needed to ensure stable pagination. This condition is generated from the (distinct) columns with lower precedence in the ORDER BY column list. For example, in “ORDER BY first_name asc, ssn desc”, multiple records may exist with the same ‘first_name’ value. The distinct column ‘ssn’ in the order definition will be the tie-breaker. If no distinct column is defined in the order definition, the PK will be the tie-breaker.



16
17
18
19
20
21
# File 'lib/rotulus/column_condition_builder.rb', line 16

def initialize(column, value, direction, tie_breaker_sql = nil)
  @column = column
  @value = value
  @direction = direction
  @tie_breaker_sql = tie_breaker_sql
end

Instance Method Details

#buildObject



23
24
25
26
27
# File 'lib/rotulus/column_condition_builder.rb', line 23

def build
  return filter_condition unless column.nullable?

  nullable_filter_condition
end