Skip to content

Rodrigo Urubatan – About Code

Helping ruby developers to use the best tools for each job so they can solve hard problems, with less bugs and have more free time.

Menu
  • Home
  • My last presentations
  • About
  • Privacy Policy
Menu

rails_db – and easy way to add an SQL interface to your Rails App

Posted on 2018-08-08 by Rodrigo Urubatan

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

Related

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent posts

  • Why Embrace Nesting in Ruby Modules?
  • An easy way to have a local “Github Copilot” for free
  • SPA without touching Javascript – The magic of Ruby on rails and Hotwire
  • I see Dead Jobs everywhere (sidekiq DeadSet)
  • Quick tips that help: rails notes

Arquives

  • May 2024
  • April 2024
  • February 2023
  • January 2023
  • December 2022
  • June 2021
  • March 2020
  • January 2020
  • July 2019
  • June 2019
  • May 2019
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • February 2018
  • January 2018
  • November 2017
  • August 2015
  • August 2014
  • July 2014
  • August 2007

Categories

  • AI
  • articles
  • cfp
  • firebase
  • gems
  • git
  • opinion
  • presentations
  • projects
  • rails6
  • ruby
  • Sem categoria
  • server-api
  • tutorials
  • Uncategorized
© 2025 Rodrigo Urubatan – About Code | Powered by Minimalist Blog WordPress Theme