refactor db.js