Class: TypedDag::Sql::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/typed_dag/sql/helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Helper

Returns a new instance of Helper.



2
3
4
# File 'lib/typed_dag/sql/helper.rb', line 2

def initialize(configuration)
  self.configuration = configuration
end

Instance Method Details

#count_columnObject



26
27
28
# File 'lib/typed_dag/sql/helper.rb', line 26

def count_column
  configuration.count_column
end

#exactly_one_type_column_eql_1(prefix = '') ⇒ Object



54
55
56
# File 'lib/typed_dag/sql/helper.rb', line 54

def exactly_one_type_column_eql_1(prefix = '')
  type_columns.map { |column| "#{prefix}#{column} = 1" }.join(' XOR ')
end

#from_columnObject



18
19
20
# File 'lib/typed_dag/sql/helper.rb', line 18

def from_column
  configuration.from_column
end

#mysql_db?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/typed_dag/sql/helper.rb', line 58

def mysql_db?
  ActiveRecord::Base.connection.adapter_name == 'Mysql2'
end

#node_table_nameObject



10
11
12
# File 'lib/typed_dag/sql/helper.rb', line 10

def node_table_name
  configuration.node_table_name
end

#sum_of_columns(columns, prefix = '') ⇒ Object



50
51
52
# File 'lib/typed_dag/sql/helper.rb', line 50

def sum_of_columns(columns, prefix = '')
  columns.map { |column| "#{prefix}#{column}" }.join(' + ')
end

#sum_of_type_columns(prefix = '') ⇒ Object



46
47
48
# File 'lib/typed_dag/sql/helper.rb', line 46

def sum_of_type_columns(prefix = '')
  sum_of_columns(type_columns, prefix)
end

#table_nameObject



6
7
8
# File 'lib/typed_dag/sql/helper.rb', line 6

def table_name
  configuration.edge_table_name
end

#to_columnObject



14
15
16
# File 'lib/typed_dag/sql/helper.rb', line 14

def to_column
  configuration.to_column
end

#type_columnsObject



22
23
24
# File 'lib/typed_dag/sql/helper.rb', line 22

def type_columns
  configuration.type_columns
end

#type_select_listObject



30
31
32
# File 'lib/typed_dag/sql/helper.rb', line 30

def type_select_list
  type_columns.join(', ')
end

#type_select_summed_columns(prefix1, prefix2) ⇒ Object



34
35
36
37
38
# File 'lib/typed_dag/sql/helper.rb', line 34

def type_select_summed_columns(prefix1, prefix2)
  type_columns
    .map { |column| "#{prefix1}.#{column} + #{prefix2}.#{column} " }
    .join(', ')
end

#type_select_summed_columns_aliased(prefix1, prefix2) ⇒ Object



40
41
42
43
44
# File 'lib/typed_dag/sql/helper.rb', line 40

def type_select_summed_columns_aliased(prefix1, prefix2)
  type_columns
    .map { |column| "(#{prefix1}.#{column} + #{prefix2}.#{column}) #{column}" }
    .join(', ')
end