# Rails DB Please **share** this gem with your friends to get more feedback. I would really appreciate for the gem review if you have a blog. If you have ideas - please create an issue or contact me by email: `igorkasyanchuk[@]gmail.com`. [](https://badge.fury.io/rb/rails_db) [](https://www.railsjazz.com) [](https://www.patreon.com/igorkasyanchuk) [](https://buymeacoffee.com/igorkasyanchuk)    Quick way to inspect your Rails database **http://localhost:12345/rails/db**, see content of tables, export them to CSV, EXPLAIN SQL and run SQL queries. Demo available on: https://rails-db.herokuapp.com/rails/db/ Video Demos: https://youtu.be/TYsRxXRFp1g, https://youtu.be/dfViQPZw9zE ## Requirements Supports: PostgreSQL, MySQL, SQLite. Not sure about other adapters. Since gem is using ActiveRecord it will work with others DBs. For older versions of Rails (Rails 3.2, 4.X) please user `gem "rails_db", "1.6"`. ## Note (!) Gem works with ruby 1.9.3 but you need to use kaminari < 1.0.0 gem and rails_db <= 1.6. Please add to gemfile `gem 'kaminari', '< 1.0.0'`. ## Main Features * command line tools `railsdb` and `runsql` to run app and sql for your apps. * view content and schema of DB tables (including indexes) * create, edit content * sort content of DB tables * filtering data (multiple filters supported too) * execute SQL queries * autocomplete for SQL queries * filter tables for easier navigation * show/hide columns in tables * use history of you SQL queries * see EXPLAIN results for your queries * export data to CSV and Excel * import SQL files * expand/collapse sidebar * hide/show columns * allow access for current user for example with appropriate role * added HTTP_BASIC auth for Rails DB * ability to turn on/off using initializer * white/black list of tables * data-tables inside your app * ajax-ify Rails DB * delete records, truncate tables * visualize SQL schema (future) * CRUD for table records (future) ## Install Add this to the development group in your `Gemfile` For all environments (be careful with production environment): ```ruby # Rails >= 6 gem 'rails_db' # Rails < 6 gem 'rails_db', '2.2.1' ``` Or only for development: ```ruby group :development do # Rails >= 6 # and there are is a big change it will work with Rails 5.2 too gem 'rails_db' # Rails < 6 gem 'rails_db', '2.2.1' end ``` Run `bundle install` Visit **`http://localhost:3000/rails/db`** and you will see your database tables and SQL editors. > Use port 12345 if running in 'standalone' mode Optionally, add `gem 'caxlsx_rails'` to your application's Gemfile to be able to export to excel `.xlsx` files. ## Customization If you want to customize gem (create initializer) run in console: rails g rails_db initializer If will create file config/initializers/rails_db.rb. ### Options * **enabled** - enable or disable gem (default: true). * **automatic_routes_mount** - automatically mount engine routes in your app (default: true). * **http_basic_authentication_enabled** - Enable HTTP_BASIC authentication (default: false). * **http_basic_authentication_user_name** - HTTP_BASIC authentication user name. * **http_basic_authentication_password** - HTTP_BASIC authentication password. * **black_list_tables** - black list for tables (hide tables from sidebar). * **white_list_tables** - black list for tables (show only these tables in sidebar). * **verify_access_proc** - allow access by specific conditions, for example by role for current_user, or you can use for example Pundit here (default: `proc { |controller| true }`) * **sandbox** - allow only read-only queries (https://github.com/igorkasyanchuk/rails_db/pull/122) If you want to add routes manually (or customize the mounted location) you need to first turn off automatic_routes_mount and then add to your `routes.rb` ```ruby mount RailsDb::Engine => '/rails/db', :as => 'rails_db' ``` If you wanted to only allow access to admins and, for example, you are using Devise you could do following (in `config/initializers/rails_db.rb`) ```ruby config.verify_access_proc = proc { |controller| controller.current_user.admin? } ``` ## Data Tables You can easily embed data-tables into your App with content from DB. You can build data tables for the whole Table, Table with specific columns or based on SQL query. Below you can see samples on how you can embed data-tables directly in your app. ```erb
](https://www.railsjazz.com/?utm_source=github&utm_medium=bottom&utm_campaign=rails_db)
[](https://buymeacoffee.com/igorkasyanchuk)