Method: SqliteRam#dump_tables
- Defined in:
- lib/free_zipcode_data/sqlite_ram.rb
#dump_tables(path) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/free_zipcode_data/sqlite_ram.rb', line 23 def dump_tables(path) tables = conn.execute('select name from sqlite_master where type = "table"') sql = nil tables.each do |table_array| table = table_array.first headers_sql = "pragma table_info('#{table}')" header = conn.execute(headers_sql).map { |e| e[1] } CSV.open(File.join(path, "#{table}.csv"), 'w') do |csv| csv << header sql = "select * from #{table}" conn.execute(sql).each do |row_array| csv << row_array end end end end |