Sha256: 59aea5719f7dfdf3493188fb61df2e769df68a3c13f921b4df76e18f17fb0db4
Contents?: true
Size: 1.1 KB
Versions: 13
Compression:
Stored size: 1.1 KB
Contents
#!/usr/bin/env ruby require 'active_record' require 'erb' require 'yaml' require 'terminal-table' require_relative "../lib/rails_db" debug = false ENGINE_ROOT = File.expand_path('../..', __FILE__) ENGINE_PATH = File.expand_path('../../lib/rails_db/engine', __FILE__) require "#{ENGINE_ROOT}/lib/ext/string_ext" require "#{ENGINE_ROOT}/lib/libs" database_yml = ::File.expand_path(File.join('.', 'config', 'database.yml')) app_path = ::File.expand_path(File.join('.')) db_conf = YAML.load(ERB.new(File.open(database_yml).read).result) || {} env = ENV['RAILS_ENV'] || ENV['ENV'] || 'development' db_env = db_conf[env] if db_env['adapter'] == 'sqlite3' db_env['database'] = "#{app_path}/#{db_env['database']}" end if debug puts "ENV: #{db_env.inspect}" end ActiveRecord::Base.establish_connection(db_env) RailsDb.use_default_configuration! sql = "#{ARGV[0]}".strip puts "Executing: #{sql}".red sql_query = RailsDb::SqlQuery.new(sql).execute rows = sql_query.data.rows cols = sql_query.data.columns if rows.any? table = Terminal::Table.new rows: rows, headings: cols puts table else puts [] end
Version data entries
13 entries across 13 versions & 1 rubygems