Sometimes you just want a Query interface for your app database and in the machine you are working you do not have anything similar to MySQLWorkbench or the uglier pgAdmin for postgres (I prefer the postgres database, but pgAdmin is still really ugly)
Or you are completely crazy and want to expose your database in your app, but who am I to judge 😀
Anyway, this gem is really cool, you can use in your dev environment as a replacement for a database GUI, just:
gem install rails_db rails_db
and you can open your browser to http://localhost:12345/rails/db and you’ll have something similar to this:
You can click in the SQL Editor and write your queries using the browser, or click on the table names and navigate through the table contents.
Another option is to use the command like “runsql” and use the rails_db infrastructure to run a query and print the results in your pretty console window using the database.yml from your project.
If you decide to add the rails_db gem to your Gemfile, you’ll get more cool features, like the ‘rails_db_data_table’ and ‘rails_db_data_table_sql’ helpers for your ERB files, that will print a pretty HTML table from your database into any page you want.
Also if you added the gem to your app, remember to generate the initializer to fix the default config
rails g rails_db initializer
Then open the generated config/initializers/rails_db.rb and setup some configs, I suggest adding the verify_access_proc and http_basic_authentication_enabled, is you want to add routes manually, disable the automatic_routes_mount and add the following to your routes file:
mount RailsDb::Engine => '/rails/db', :as => 'rails_db'
After that, you can enjoy giving some users full access to your database, and hope no one runs any of the following commands 😀
DROP DATABASE yourapp; DROP TABLE users; DELETE FROM financial_transactions; //forgot the WHERE clause
I think this gem is really cool, and I’ll probably use it in some minor personal projects for testing, and maybe it will replace in some environment my desktop sql tool (talking about that, anyone uses a multi database, good sql admin tool?)
And of course, if you have any ideas on how to improve this gem, or found a bug, check the gem’s github page RailsDB