{"size": 556, "ext": "js", "max_stars_repo_path": "db.js", "max_stars_repo_name": "honestxll/vue-notes", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "db.js", "max_issues_repo_name": "honestxll/vue-notes", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "db.js", "max_forks_repo_name": "honestxll/vue-notes", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.1666666667, "max_line_length": 87, "alphanum_fraction": 0.6618705036}
const databaseInitalize = () => {
  const notes = db.getCollection('notes');
  notes || db.addCollection('notes');
}

const db = new loki('notes', {
  autoload: true,
  autoloadCallback: databaseInitalize,
  autosave: true,
  autosaveInterval: 3000
});

// lokijs 的 curd 方法和 mongodb 基本一样
// 可以使用 notes.clear() 来清空数据库

const loadCollection = (collection) => {
  return new Promise(resolve => {
    db.loadDatabase({}, () => {
      const _collection = db.getCollection(collection) || db.addCollection(collection);
      resolve(_collection);
    });
  })
}
