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
171 172 173 |
# File 'lib/ydd/serialization_helper.rb', line 171 def self.after_table(io, table) end |
.before_table(io, table) ⇒ Object
159 160 161 |
# File 'lib/ydd/serialization_helper.rb', line 159 def self.before_table(io, table) end |
.dump(io) ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/ydd/serialization_helper.rb', line 163 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
182 183 184 185 186 187 |
# File 'lib/ydd/serialization_helper.rb', line 182 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
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/ydd/serialization_helper.rb', line 194 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
189 190 191 |
# File 'lib/ydd/serialization_helper.rb', line 189 def self.table_column_names(table) YDD.connection.columns(table).map { |c| c.name } end |
.table_record_count(table) ⇒ Object
210 211 212 |
# File 'lib/ydd/serialization_helper.rb', line 210 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
175 176 177 178 179 180 |
# File 'lib/ydd/serialization_helper.rb', line 175 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 |