Class: Thorderbolt::BaseQueryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/thorderbolt/base_query_builder.rb

Overview

Builds full query for performing custom ordering

Direct Known Subclasses

OrderAnyQueryBuilder, OrderQueryBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name:, attribute:, values:) ⇒ BaseQueryBuilder

Returns a new instance of BaseQueryBuilder.



8
9
10
11
12
# File 'lib/thorderbolt/base_query_builder.rb', line 8

def initialize(table_name:, attribute:, values:)
  @table_name = table_name
  @attribute = attribute
  @values = values
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



6
7
8
# File 'lib/thorderbolt/base_query_builder.rb', line 6

def attribute
  @attribute
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



6
7
8
# File 'lib/thorderbolt/base_query_builder.rb', line 6

def table_name
  @table_name
end

#valuesObject (readonly)

Returns the value of attribute values.



6
7
8
# File 'lib/thorderbolt/base_query_builder.rb', line 6

def values
  @values
end

Instance Method Details

#buildObject

result example: CASE

WHEN 'cities'.'name'='City 1' THEN 0
WHEN 'cities'.'name'='City 5' THEN 1
ELSE 2

END ASC



20
21
22
23
24
25
# File 'lib/thorderbolt/base_query_builder.rb', line 20

def build
  conditions = build_conditions
  when_queries = build_when_then_part(conditions)
  case_query = build_case_else(when_queries)
  Arel.sql("#{case_query} ASC")
end