<commit_before>var migrit     = require('migrit')
  , uuid       = require('node-uuid')
  , _          = require('underscore')
  ;

function model(name, env){
  this.name  = name;
  this.env   = env;
}


model.prototype.get = function(where){
  var name = this.name
    , env  = this.env
    ;
  if(where && where.id){
    where = " WHERE id = '"+where.id+"'"; 
  }else{
    where = ''
  }
  return migrit.config
    .then(function(conf){
      migrit.sql.connect(conf, env);
      return migrit.sql.query("SELECT * FROM "+name+where)
    })
}

model.prototype.push = function(item){
  var name  = this.name
    , env   = this.env
    , _this = this
    ;
  item.id = uuid.v4();
  return migrit.config
    .then(function(conf){
      migrit.sql.connect(conf, env);
      var sql = "INSERT INTO "+name
        , values = _.values(item)
                    .map(function(i){
                      return("'"+i+"'");
                    }).join(",");
        ;
      sql = sql+"("+_.keys(item).join(",")+")VALUES("+values+")";
      return migrit.sql.query(sql);
    })
    .then(function(){
      return _this.get(item);
    })
    .catch(function(err){
      console.log(err);
    });
}

model.prototype.put = function(id, item){
  var name  = this.name
    , env   = this.env
    , _this = this
    ;
  delete item.id
  return migrit.config
    .then(function(conf){
      migrit.sql.connect(conf, env);
      var sql = "UPDATE "+name+" SET "
        , values = _.map(item, function(val, key){
                    return(key+" = '"+val+"'");
                  }).join(",");
        ;
      sql = sql+values+" WHERE id = '"+id+"'";
      return migrit.sql.query(sql);
    })
    .then(function(){
      return _this.get({id: id});
    })
}

model.prototype.delete = function(id){
  var name  = this.name
    , env   = this.env
    ;
  return migrit.config
    .then(function(conf){
      var sql = "DELETE FROM "+name+" WHERE id = '"+id+"'"
      migrit.sql.connect(conf, env);
      return migrit.sql.query(sql);
    })
}

module.exports = model;<commit_msg>developing model-behavior outside the model-behavior repo<commit_after>var migrit     = require('migrit')
  , uuid       = require('node-uuid')
  , _          = require('underscore')
  ;

function model(name, env){
  this.name  = name;
  this.env   = env;
}

model.prototype.get = function(item){
  var where = ""
    , sql
    ;
  if(item){
    where = " WHERE "; 
    where = where + _.map(item, function(val, key){
      return key+" = '"+val+"'"
    }).join(" AND ");
  }
  sql = "SELECT * FROM "+this.name+where
  return this.sql(sql)
}

model.prototype.push = function(item){
  item.id = uuid.v4();
  var _this  = this
    , sql    = "INSERT INTO "+this.name
    , values = _.values(item)
                .map(function(i){
                  return("'"+i+"'");
                }).join(",");
    ;
  sql = sql+"("+_.keys(item).join(",")+")VALUES("+values+")";
  return this.sql(sql)
             .then(function(){
               return _this.get({id: item.id});
             })
}

model.prototype.put = function(id, item){
  delete item.id
  var _this = this
    , sql = "UPDATE "+this.name+" SET "
    , values = _.map(item, function(val, key){
                return(key+" = '"+val+"'");
              }).join(",")
    ;

  return this.sql(sql+values+" WHERE id = '"+id+"'")
    .then(function(){
      return _this.get({id: id});
    })
}

model.prototype.delete = function(id){
  return this.sql("DELETE FROM "+this.name+" WHERE id = '"+id+"'");
}

model.prototype.sql = function(sql){
  var env = this.env;
  return migrit.config
    .then(function(conf){
      migrit.sql.connect(conf, env);
      return migrit.sql.query(sql);
    })
}

module.exports = model;
{'fraction_non_alphanumeric': 0.1850362027353178, 'fraction_numerical': 0.0005363368195226602, 'mean_word_length': 2.169073916737468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6491482', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1272, 'n_words': 252}