{"size": 702, "ext": "js", "max_stars_repo_path": "models/database.js", "max_stars_repo_name": "leemahoney3/Bewk", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models/database.js", "max_issues_repo_name": "leemahoney3/Bewk", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models/database.js", "max_forks_repo_name": "leemahoney3/Bewk", "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": 15.2608695652, "max_line_length": 67, "alphanum_fraction": 0.6481481481}
'use strict';

/* Database class, inherits lowdb */

const lowdb     = require('lowdb');
const fileASync = require('lowdb/lib/file-async');


class Database {

  constructor(file, defaults) {

    this.db = lowdb(file, { storage: fileASync });
    this.db.defaults(defaults).value();

  }

  add(collection, object) {

    this.db.get(collection).push(object).value();

  }

  remove(collection, object) {

    this.db.get(collection).remove(object).value();

  }

  findAll(collection) {

    return this.db.get(collection).value();

  }

  findOneBy(collection, filter) {

    const results = this.db.get(collection).filter(filter).value();
    return results[0];

  }

}

module.exports = Database;
