moving db functions out of the server