wrapped  query into a function.