Class: ShopifyTransporter::Exporters::Magento::DatabaseTableExporter
- Inherits:
-
Object
- Object
- ShopifyTransporter::Exporters::Magento::DatabaseTableExporter
- Defined in:
- lib/shopify_transporter/exporters/magento/database_table_exporter.rb
Constant Summary collapse
- BATCH_SIZE =
1000- DB_CACHE_FOLDER =
'./cache/magento_db'
Instance Method Summary collapse
- #export_table(table_name, index_column) ⇒ Object
-
#initialize(database_adapter) ⇒ DatabaseTableExporter
constructor
A new instance of DatabaseTableExporter.
Constructor Details
#initialize(database_adapter) ⇒ DatabaseTableExporter
Returns a new instance of DatabaseTableExporter.
11 12 13 14 |
# File 'lib/shopify_transporter/exporters/magento/database_table_exporter.rb', line 11 def initialize(database_adapter) @database_adapter = database_adapter FileUtils.mkdir_p(DB_CACHE_FOLDER) end |
Instance Method Details
#export_table(table_name, index_column) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/shopify_transporter/exporters/magento/database_table_exporter.rb', line 16 def export_table(table_name, index_column) export_file_path = "#{DB_CACHE_FOLDER}/#{table_name}.csv" return if File.file? export_file_path index_key = index_column.to_sym @database_adapter.connect do |db| ordered_table = db .from(table_name) .order(index_key) headers = ordered_table.columns write_headers(export_file_path, headers) in_batches(ordered_table, index_key) do |batch| write_batch(export_file_path, headers, batch) end end end |