<commit_before>SequelizeHelper = {
  log: function(obj) {
    var sys = require("sys")
    sys.puts(sys.inspect(obj))
  },
  
  evaluateTemplate: function(template, replacements) {
    var result = template
    SequelizeHelper.Hash.keys(replacements).forEach(function(key) {
      result = result.replace("%{" + key + "}", replacements[key])
    })
    return result
  },
  
  SQL: {
    manyToManyTableName: function(t1, t2) {
      return [t1.tableName, t2.tableName].sort().join("")
    },
    
    asTableIdentifier: function(name) {
      return name.toLowerCase().replace(/s$/, "") + "Id"
    },
    
    addPrefix: function(prefix, string) {
      return prefix + string[0].toUpperCase() + string.replace(/^./, "")
    },
    
    asTableName: function(name) {
      return name + "s"
    },
    
    asSqlDate: function(date) {
      return [
        [
          date.getFullYear(),
          ((date.getMonth() < 9 ? '0' : '') + (date.getMonth()+1)),
          ((date.getDate() < 10 ? '0' : '') + date.getDate())
        ].join("-"),
        date.toLocaleTimeString()
      ].join(" ")
    },
    
    valuesForInsertQuery: function(object) {
      var actualValues = object.values,
          result  = []

      SequelizeHelper.Hash.forEach(actualValues, function(value, key) {
        var dataType  = object.table.attributes[key]
        result.push(SequelizeHelper.SQL.transformValueByDataType(value, dataType))
      })

      return result
    },

    fieldsForInsertQuery: function(object) {
      return SequelizeHelper.Hash.keys(object.values).join(", ")
    },

    transformValueByDataType: function(value, dataType) {
      if((value == null)||(typeof value == 'undefined'))
        return "NULL"
      
      if(dataType.indexOf(Sequelize.INTEGER) > -1)
        return value
      
      if(dataType.indexOf(Sequelize.DATE) > -1)
        return ("'" + SequelizeHelper.SQL.asSqlDate(value) + "'")
      
      return ("'" + value + "'")
    },

    valuesForUpdate: function(object, options) {
      var actualValues = object.values,
          result  = []

      options = options || {}

      SequelizeHelper.Hash.forEach(actualValues, function(value, key) {
        var dataType  = object.table.attributes[key]
        result.push([key, SequelizeHelper.SQL.transformValueByDataType(value, dataType)].join(" = "))
      })

      return result.join(options.seperator || ", ")
    },
    
    hashToWhereConditions: function(conditions, attributes) {
      if(typeof conditions == 'number')
        return ('id = ' + conditions)
      else {
        var result = []
        SequelizeHelper.Hash.forEach(conditions, function(value, key) {
          result.push(key + "=" + SequelizeHelper.SQL.transformValueByDataType(value, attributes[key]))
        })
        return result.join(" AND ")
      }
    }
  },<commit_msg>use IS NULL in where clause<commit_after>SequelizeHelper = {
  log: function(obj) {
    var sys = require("sys")
    sys.puts(sys.inspect(obj))
  },
  
  evaluateTemplate: function(template, replacements) {
    var result = template
    SequelizeHelper.Hash.keys(replacements).forEach(function(key) {
      result = result.replace("%{" + key + "}", replacements[key])
    })
    return result
  },
  
  SQL: {
    manyToManyTableName: function(t1, t2) {
      return [t1.tableName, t2.tableName].sort().join("")
    },
    
    asTableIdentifier: function(name) {
      return name.toLowerCase().replace(/s$/, "") + "Id"
    },
    
    addPrefix: function(prefix, string) {
      return prefix + string[0].toUpperCase() + string.replace(/^./, "")
    },
    
    asTableName: function(name) {
      return name + "s"
    },
    
    asSqlDate: function(date) {
      return [
        [
          date.getFullYear(),
          ((date.getMonth() < 9 ? '0' : '') + (date.getMonth()+1)),
          ((date.getDate() < 10 ? '0' : '') + date.getDate())
        ].join("-"),
        date.toLocaleTimeString()
      ].join(" ")
    },
    
    valuesForInsertQuery: function(object) {
      var actualValues = object.values,
          result  = []

      SequelizeHelper.Hash.forEach(actualValues, function(value, key) {
        var dataType  = object.table.attributes[key]
        result.push(SequelizeHelper.SQL.transformValueByDataType(value, dataType))
      })

      return result
    },

    fieldsForInsertQuery: function(object) {
      return SequelizeHelper.Hash.keys(object.values).join(", ")
    },

    transformValueByDataType: function(value, dataType) {
      if((value == null)||(typeof value == 'undefined'))
        return "NULL"
      
      if(dataType.indexOf(Sequelize.INTEGER) > -1)
        return value
      
      if(dataType.indexOf(Sequelize.DATE) > -1)
        return ("'" + SequelizeHelper.SQL.asSqlDate(value) + "'")
      
      return ("'" + value + "'")
    },

    valuesForUpdate: function(object, options) {
      var actualValues = object.values,
          result  = []

      options = options || {}

      SequelizeHelper.Hash.forEach(actualValues, function(value, key) {
        var dataType  = object.table.attributes[key]
        result.push([key, SequelizeHelper.SQL.transformValueByDataType(value, dataType)].join(" = "))
      })

      return result.join(options.seperator || ", ")
    },
    
    hashToWhereConditions: function(conditions, attributes) {
      if(typeof conditions == 'number')
        return ('id = ' + conditions)
      else {
        var result = []
        SequelizeHelper.Hash.forEach(conditions, function(value, key) {
          var _value = SequelizeHelper.SQL.transformValueByDataType(value, attributes[key])
          if(_value == 'NULL') result.push(key + " IS NULL")
          else result.push(key + "=" + _value)
        })
        return result.join(" AND ")
      }
    }
  },
{'fraction_non_alphanumeric': 0.15117484450587423, 'fraction_numerical': 0.004492052522460262, 'mean_word_length': 2.4706235011990407, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2061879', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1764, 'n_words': 292}