Created
November 16, 2010 20:15
-
-
Save metalelf0/702423 to your computer and use it in GitHub Desktop.
MysqlQueryResultsFormatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MysqlQueryResultsFormatter | |
require 'terminal-table/import' | |
def print_results_of_query query | |
result = ActiveRecord::Base.connection.execute(query) | |
return nil if result.nil? | |
results_table = table do |t| | |
results = result.all_hashes | |
t.headings = results.first.keys | |
results.each do |each_row| | |
t << each_row.values | |
end | |
end | |
puts results_table | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment