DataMapper SQL Queries in Rails Console

A quick note on logging SQL queries in DataMapper 1.2 so you can see exactly what’s going on behind the scenes. Seeing the query can be beneficial in debugging when getting unexpected results or trying to increase query performance.

DataMapper::Logger.new($stdout, :debug)

Enter that at anytime while running in rails c and you should start seeing the output immediatley.

Note If you don’t see the output potentially it’s because of DM’s identiity map. In which case a new query isn’t actually being performed. Try a query that you haven’t done yet and verify the results are output. Or Simply restart the console.