<commit_before>'use strict';

class Model {

  constructor(data){
    this.DB = Model.DB;
    this.data = data || {};
  }

  schema(){
    return null;
  }

  static bindDatabase(DB){
    this.DB = DB;
    return this;
  }

  set(key, value){
    this.data[key] = value;
    return this;
  }

  get(key){
    return this.data[key];
  }

  save(callback){
    if(callback === undefined){
      callback = () => {};
    }

    if(this.data._id !== undefined){
      return this.update(callback);
    }


    this.DB.collection(this.collection()).schema(this.schema()).insert(this.data, (err, result) => {
      this.data = result.ops[0];
      callback(err, this);
    });
  }

  update(callback){
    let id = this.data._id;
    delete this.data._id;
    this.DB.collection(this.collection()).schema(this.schema()).where('id', id).update(this.data, (err, result) => {
      callback(err, this);
    });
  }

  delete(callback){
    if(this.data._id === undefined){
      throw new Error('Model: id needs to be specified before the delete method works');
    }

    if(callback === undefined){
      callback = () => {};
    }

    this.DB.collection(this.collection()).schema(this.schema()).where('_id', this.data._id).remove((err, result) => {
      callback(err, result)
    });
  }

  static find(id, callback){
    let model = new this;

    model.DB.collection(model.collection()).schema(model.schema()).model(this).where('_id', id).get((err, result) => {<commit_msg>Fixed problem where update didn't match the correct id<commit_after>'use strict';

class Model {

  constructor(data){
    this.DB = Model.DB;
    this.data = data || {};
  }

  schema(){
    return null;
  }

  static bindDatabase(DB){
    this.DB = DB;
    return this;
  }

  set(key, value){
    this.data[key] = value;
    return this;
  }

  get(key){
    return this.data[key];
  }

  save(callback){
    if(callback === undefined){
      callback = () => {};
    }

    if(this.data._id !== undefined){
      return this.update(callback);
    }


    this.DB.collection(this.collection()).schema(this.schema()).insert(this.data, (err, result) => {
      this.data = result.ops[0];
      callback(err, this);
    });
  }

  update(callback){
    let id = this.data._id;
    delete this.data._id;
    this.DB.collection(this.collection()).schema(this.schema()).where('_id', id).update(this.data, (err, result) => {
      callback(err, this);
    });
  }

  delete(callback){
    if(this.data._id === undefined){
      throw new Error('Model: id needs to be specified before the delete method works');
    }

    if(callback === undefined){
      callback = () => {};
    }

    this.DB.collection(this.collection()).schema(this.schema()).where('_id', this.data._id).remove((err, result) => {
      callback(err, result)
    });
  }

  static find(id, callback){
    let model = new this;

    model.DB.collection(model.collection()).schema(model.schema()).model(this).where('_id', id).get((err, result) => {
{'fraction_non_alphanumeric': 0.18398123324396784, 'fraction_numerical': 0.0006702412868632708, 'mean_word_length': 2.8516129032258064, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2926590', 'n_tokens_mistral': 982, 'n_tokens_neox': 950, 'n_words': 184}