Adding JSDoc comments to database.js

Also refactoring a few methods to allow custom callbacks