How to print names of all the tables in the database in MySql2 in Ruby?

388 views Asked by At

I want to create buttons (using Shoes) of all the tables in my database.

I am a beginner and this is my first GUI project 'Stock Management', I am using shoes library in Ruby and want to store and manage the data in MySql2 with Ruby. I typed some code but its not working

path/main.rb

require 'mysql2'
require 'green_shoes'

client = Mysql2::Client.new (host: "localhost",username: "root", password: "xyz", database: "Ruby")

Shoes.app do
    components = client.query("SHOW TABLES")
    components.each do |item|
        button item
    end
end`

Gives nothing.

1

There are 1 answers

4
Mureinik On

You could query them from the information_schema:

components = client.query("SELECT table_name FROM information_schema.tables")