Showing SQL Statements in script/console

December 20th, 2008 by Radar

Today keiran_nz asked how to see SQL statements that occur when running code in script/console. After a little bit of mucking around in the terminal I worked it out to be:

tail -f log/development.log & script/console

The first comment on this post Ashley Williams says you could do:

tail -f log/development.log & clear && script/console

instead, and then goes further and sticks it in an alias in your .bashrc file (presumably):

alias rcon=”tail -f log/development.log & clear && script/console”

6 Responses to “Showing SQL Statements in script/console”

  1. Ashley Williams Says:

    Awesome! Makes a cool alias (with a clear in between also):

    alias rcon=”tail -f log/development.log & clear && script/console”

    Thanks :)

  2. Radar Says:

    Hey that’s a good idea!

  3. Tim Riley Says:

    I use a different approach, sticking some stuff into $HOME/.irbrc:

    
    if ENV['RAILS_ENV']
      # Called after the irb session is initialized and Rails has been loaded
      IRB.conf[:IRB_RC] = Proc.new do
        logger = Logger.new(STDOUT)
        ActiveRecord::Base.logger = logger
        ActiveResource::Base.logger = logger
      end
    end
    

    I picked it up from one of the Rails blogs out there, probably one of these: http://delicious.com/timriley/irb

  4. Liam Morley Says:

    I’m all about the irbrc.

    if ENV.include?('RAILSENV') && !Object.constdefined?('RAILSDEFAULTLOGGER')
      require 'logger'
      RAILSDEFAULTLOGGER = Logger.new(STDOUT)
    end
    

  5. Alexwebmaster Says:

    Hello webmaster I would like to share with you a link to your site write me here preonrelt@mail.ru

  6. SQL Tutorials Says:

    Does anyone know if there is another language or set of commands beside SQL for talking with databases?

    I’m working on a project and am doing some research thanks

Leave a Reply