Refactoring database code to coffees.js