Move common database code to a base controller struct that opens and closes database connections for each request.