<commit_before>fs = require "fs"
path = require "path"
mysql = require 'mysql'
SALT_WORK_FACTOR = 10
CONFIGS = JSON.parse(fs.readFileSync(path.join __dirname, 'configs.json'), 'utf8').mysql

connection = mysql.createConnection
  host: CONFIGS.host
  database: CONFIGS.database
  user: CONFIGS.user
  password: <PASSWORD>
  port: CONFIGS.port

connection.connect (error) ->
  if error
    console.log "Connection refused to mysql: #{error.stack}"
    console.log error
  else
    console.log "Connection successful to mysql: id is #{connection.threadId}"

user =
  findOne: (obj, callback) ->
    key = null
    value = null
    for k, v of obj
      key = k
      value = v
    connection.query {
      sql: "SELECT * FROM users where #{key} = ?"
      values: [value]
    }, (error, result) ->
      callback error, result[0]

  findAll: (callback) ->
    connection.query {
      sql: "SELECT * FROM users"
    }, (error, results) ->
      callback error, results

  addUser: (user, callback) ->
    connection.query {
      sql: "INSERT INTO users (`username`, `password`, `firstname`, `lastname`, `street`, `zip`, `location`) VALUES (?, ?, ?, ?, ?, ?, ?)",
      values: [
        user.username
        user.password
        user.firstname
        user.lastname
        user.street || ''
        user.zip || ''
        user.location || ''
      ]
    }, (error, result) ->
      callback error, result

  updateUser: (user, callback) ->
    id = user.id
    connection.query {
      sql: "UPDATE users SET username=?, password=?, firstname=?, lastname=?, street=?, zip=?, location=? WHERE id=#{id}",
      values: [
        user.username
        user.password
        user.firstname
        user.lastname
        user.street || ''
        user.zip || ''
        user.location || ''
      ]
    }, (error, result) ->
      callback error, result

  deleteUser: (userId, callback) ->
    connection.query {
      sql: "DELETE FROM users where id = ?",
      values: [userId]
    }, (error, result) -><commit_msg>updateUser throw error<commit_after>fs = require "fs"
path = require "path"
mysql = require 'mysql'
SALT_WORK_FACTOR = 10
CONFIGS = JSON.parse(fs.readFileSync(path.join __dirname, 'configs.json'), 'utf8').mysql

connection = mysql.createConnection
  host: CONFIGS.host
  database: CONFIGS.database
  user: CONFIGS.user
  password: <PASSWORD>
  port: CONFIGS.port

connection.connect (error) ->
  if error
    console.log "Connection refused to mysql: #{error.stack}"
    console.log error
  else
    console.log "Connection successful to mysql: id is #{connection.threadId}"

user =
  findOne: (obj, callback) ->
    key = null
    value = null
    for k, v of obj
      key = k
      value = v
    connection.query {
      sql: "SELECT * FROM users where #{key} = ?"
      values: [value]
    }, (error, result) ->
      callback error, result[0]

  findAll: (callback) ->
    connection.query {
      sql: "SELECT * FROM users"
    }, (error, results) ->
      callback error, results

  addUser: (user, callback) ->
    connection.query {
      sql: "INSERT INTO users (`username`, `password`, `firstname`, `lastname`, `street`, `zip`, `location`) VALUES (?, ?, ?, ?, ?, ?, ?)",
      values: [
        user.username
        user.password
        user.firstname
        user.lastname
        user.street || ''
        user.zip || ''
        user.location || ''
      ]
    }, (error, result) ->
      callback error, result

  updateUser: (user, callback) ->
    id = user.id
    callback(throw new Error "Error updating user, no id specified") if !id
    connection.query {
      sql: "UPDATE users SET username=?, password=?, firstname=?, lastname=?, street=?, zip=?, location=? WHERE id=#{id}",
      values: [
        user.username
        user.password
        user.firstname
        user.lastname
        user.street || ''
        user.zip || ''
        user.location || ''
      ]
    }, (error, result) ->
      callback error, result

  deleteUser: (userId, callback) ->
    connection.query {
      sql: "DELETE FROM users where id = ?",
      values: [userId]
    }, (error, result) ->
{'fraction_non_alphanumeric': 0.1424750790177486, 'fraction_numerical': 0.0019450522732798443, 'mean_word_length': 2.4455611390284755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '1060575', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1236, 'n_words': 347}