Class: TypedDag::Sql::Helper
- Inherits:
-
Object
- Object
- TypedDag::Sql::Helper
- Defined in:
- lib/typed_dag/sql/helper.rb
Instance Method Summary collapse
- #count_column ⇒ Object
- #exactly_one_type_column_eql_1(prefix = '') ⇒ Object
- #from_column ⇒ Object
-
#initialize(configuration) ⇒ Helper
constructor
A new instance of Helper.
- #mysql_db? ⇒ Boolean
- #node_table_name ⇒ Object
- #sum_of_columns(columns, prefix = '') ⇒ Object
- #sum_of_type_columns(prefix = '') ⇒ Object
- #table_name ⇒ Object
- #to_column ⇒ Object
- #type_columns ⇒ Object
- #type_select_list ⇒ Object
- #type_select_summed_columns(prefix1, prefix2) ⇒ Object
- #type_select_summed_columns_aliased(prefix1, prefix2) ⇒ Object
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_column ⇒ Object
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_column ⇒ Object
18 19 20 |
# File 'lib/typed_dag/sql/helper.rb', line 18 def from_column configuration.from_column end |
#mysql_db? ⇒ 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_name ⇒ Object
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_name ⇒ Object
6 7 8 |
# File 'lib/typed_dag/sql/helper.rb', line 6 def table_name configuration.edge_table_name end |
#to_column ⇒ Object
14 15 16 |
# File 'lib/typed_dag/sql/helper.rb', line 14 def to_column configuration.to_column end |
#type_columns ⇒ Object
22 23 24 |
# File 'lib/typed_dag/sql/helper.rb', line 22 def type_columns configuration.type_columns end |
#type_select_list ⇒ Object
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 |