it would be great if we could create a generic helper function to do this kind of thing.  I know it's kind of specific to the actual db query, so maybe it's not possible.  but worth considering.