Class: Exwiw::TableConfig
- Inherits:
-
Object
- Object
- Exwiw::TableConfig
- Includes:
- Serdes
- Defined in:
- lib/exwiw/table_config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #belongs_to(table_name) ⇒ Object
- #build_extract_query(extract_target_table, extract_target_ids, tables_by_name) ⇒ Object
- #column_names ⇒ Object
Class Method Details
.from_symbol_keys(hash) ⇒ Object
13 14 15 |
# File 'lib/exwiw/table_config.rb', line 13 def self.from_symbol_keys(hash) from(hash.transform_keys(&:to_s)) end |
Instance Method Details
#belongs_to(table_name) ⇒ Object
21 22 23 |
# File 'lib/exwiw/table_config.rb', line 21 def belongs_to(table_name) belongs_tos.find { |relation| relation.table_name == table_name } end |
#build_extract_query(extract_target_table, extract_target_ids, tables_by_name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/exwiw/table_config.rb', line 25 def build_extract_query(extract_target_table, extract_target_ids, tables_by_name) # target is itself if name == extract_target_table return [{ from: name, where: [{ primary_key => extract_target_ids }], join: [], select: column_names, }] end # it is not related to target table if belongs_to.empty? return [{ from: name, where: [], join: [], select: column_names, }] end belongs_to_extract_target_table = belongs_tos.find { |relation| relation.table_name == extract_target_table } if belongs_to_extract_target_table key = belongs_to_extract_target_table.foreign_key return [{ from: name, where: [{ key => extract_target_ids }], join: [], select: column_names }] end ret = compute_dependency_to_table(extract_target_table, tables_by_name) if ret.empty? [{ from: name, where: [], join: [], select: column_names, }] else last = ret.last last[:where] = [{ last[:foreign_key] => extract_target_ids }] ret end end |
#column_names ⇒ Object
17 18 19 |
# File 'lib/exwiw/table_config.rb', line 17 def column_names columns.map(&:name) end |