Database query helper.