move DB logic out of app.js into modules