Refactor all SQL specific things to db.js