Class: YDD::SerializationHelper::Dump
- Inherits:
-
Object
- Object
- YDD::SerializationHelper::Dump
- Defined in:
- lib/ydd/serialization_helper.rb
Direct Known Subclasses
Class Method Summary collapse
- .after_table(io, table) ⇒ Object
- .before_table(io, table) ⇒ Object
- .dump(io) ⇒ Object
- .dump_table(io, table) ⇒ Object
- .each_table_page(table, records_per_page = 1000) ⇒ Object
- .table_column_names(table) ⇒ Object
- .table_record_count(table) ⇒ Object
- .tables ⇒ Object
Class Method Details
.after_table(io, table) ⇒ Object
128 129 130 |
# File 'lib/ydd/serialization_helper.rb', line 128 def self.after_table(io, table) end |
.before_table(io, table) ⇒ Object
116 117 118 |
# File 'lib/ydd/serialization_helper.rb', line 116 def self.before_table(io, table) end |
.dump(io) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/ydd/serialization_helper.rb', line 120 def self.dump(io) tables.each do |table| before_table(io, table) dump_table(io, table) after_table(io, table) end end |
.dump_table(io, table) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/ydd/serialization_helper.rb', line 139 def self.dump_table(io, table) return if table_record_count(table).zero? dump_table_columns(io, table) dump_table_records(io, table) end |
.each_table_page(table, records_per_page = 1000) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/ydd/serialization_helper.rb', line 151 def self.each_table_page(table, records_per_page = 1000) total_count = table_record_count(table) pages = (total_count.to_f / records_per_page).ceil - 1 id = table_column_names(table).first boolean_columns = SerializationHelper::Utils.boolean_columns(table) quoted_table_name = SerializationHelper::Utils.quote_table(table) base_query = "SELECT * FROM #{quoted_table_name} ORDER BY #{id}" 0.upto(pages) do |page| sql = YDD.connection.add_limit_offset! base_query.dup, :limit => records_per_page, :offset => records_per_page * page records = YDD.connection.select_all(sql) records = SerializationHelper::Utils.convert_booleans(records, boolean_columns) yield records end end |
.table_column_names(table) ⇒ Object
146 147 148 |
# File 'lib/ydd/serialization_helper.rb', line 146 def self.table_column_names(table) YDD.connection.columns(table).map { |c| c.name } end |
.table_record_count(table) ⇒ Object
167 168 169 |
# File 'lib/ydd/serialization_helper.rb', line 167 def self.table_record_count(table) YDD.connection.select_one("SELECT COUNT(*) FROM #{SerializationHelper::Utils.quote_table(table)}").values.first.to_i end |
.tables ⇒ Object
132 133 134 135 136 137 |
# File 'lib/ydd/serialization_helper.rb', line 132 def self.tables base_tables = YDD.connection.tables base_tables &= YDD.tables if YDD.tables.present? base_tables.reject! { |table| YDD.schema_tables.include?(table) } if YDD.skip_schema? base_tables end |