Simplify database query code.