Module: ExecuteSql::ConsoleMethods

Included in:
ExecuteSql
Defined in:
lib/execute_sql.rb

Instance Method Summary collapse

Instance Method Details

#execute_sql(sql, mode: :print) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/execute_sql.rb', line 25

def execute_sql(sql, mode: :print)
  sql_query = ExecuteSql::SqlQuery.new("#{sql}".strip).execute
  rows = sql_query.data.rows
  cols = sql_query.data.columns
  case mode.to_s
  when 'print'
    puts Terminal::Table.new(rows: rows, headings: cols)
  when 'raw'
    rows
  when 'single'
    rows.flatten[0]
  when 'none'
    nil
  else
    []
  end
end

#run(sql, *args) ⇒ Object



43
44
45
# File 'lib/execute_sql.rb', line 43

def run(sql, *args)
  execute_sql(sql, *args)
end