Move query declaration out of route handler