Database Metaprogramming

In the absence of anything really pressing to talk about, I thought I'd share two tidbits I found via my feed reader.

J. Scott Johnson had a great post at his blog about SQL_CALC_FOUND_ROWS and Faster Count(*) Alternatives. If you've ever had to write some code that loops through a database searching for counts that match specific where clauses, then go and read this posting. It just makes so much sense and I had always suspected there was a better way to do the old "query once to get the data you want and then query again to get the count that matches that data" trick. I must get my SQL skills boosted up one of these days.

The second posting is from Josh Susser where he talks about how ActiveRecord's dynamic finders work. For those not wiling to go through the archives, ActiveRecord is an Object Relational Mapping wrapper for database connections that makes using databases in your Rails code insanely easy.