<commit_before># Description:
#   Database handler for postgresql
#   app name: saborunayo
#
# Functions:
#   sendQuery(query)
#   getGithubName(yo_name)
#   writeData(yo_name, github_name)
#
# Author:
#   @sota1235

pg = require 'pg'

module.exports = class Db_Handler

  constructor: ->
    @db_url = process.env.DATABASE_URL
    @db_name = "user_list"
    @client = new pg.Client @db_url

  # Send query to database
  sendQuery: (command, callback = ->) ->
    client = new pg.Client @db_url
    client.connect (err) ->
      if err
        calback [err, null]
        return
      client.query command, (err, result) ->
        if err
          callback [err, null]
          return
        callback [null, result.rows]
        return

  # Get data from database
  getGithubName: (yo_name, callback = ->) ->
    query = "SELECT github_name FROM #{@db_name} WHERE yo_name='#{yo_name}';"
    @sendQuery query, (data) ->
      callback data[0], data[1]
      return

  # Insert data to database
  # yo_name -> yo_name
  # github_name -> github_name
  writeData: (yo_name, github_name, callback = ->) ->
    query = "INSERT INTO #{@db_name} (yo_name, github_name) values ('#{yo_name}', '#{github_name}');"

    # TODO: Yoアカウントがあるかどうか検証
    # TODO: githubアカウントが実在するかどうか検証
    @sendQuery query, (data) ->
      callback data[0], data[1]
      return

  # Delete data in database
  deleteData: (yo_name, callback = ->) ->
    query = "DELETE FROM #{@db_name} WHERE yo_name='#{yo_name}';"
    @sendQuery query, (data) ->
      callback data[0], data[1]<commit_msg>fix db_handler.coffee | JSON.strigifyすることでデータ表示を解決<commit_after># Description:
#   Database handler for postgresql
#   app name: saborunayo
#
# Functions:
#   sendQuery(query)
#   getGithubName(yo_name)
#   writeData(yo_name, github_name)
#
# Author:
#   @sota1235

pg = require 'pg'

module.exports = class Db_Handler

  constructor: ->
    @db_url = process.env.DATABASE_URL
    @db_name = "user_list"
    @client = new pg.Client @db_url

  # Send query to database
  sendQuery: (command, callback = ->) ->
    client = new pg.Client @db_url
    client.connect (err) ->
      if err
        calback [err, null]
        return
      client.query command, (err, result) ->
        if err
          callback [err, null]
          return
        callback [null, result.rows]
        return

  # Get data from database
  getGithubName: (yo_name, callback = ->) ->
    query = "SELECT github_name FROM #{@db_name} WHERE yo_name='#{yo_name}';"
    @sendQuery query, (data) ->
      callback data[0], JSON.stringify data[1]
      return

  # Insert data to database
  # yo_name -> yo_name
  # github_name -> github_name
  writeData: (yo_name, github_name, callback = ->) ->
    query = "INSERT INTO #{@db_name} (yo_name, github_name) values ('#{yo_name}', '#{github_name}');"

    # TODO: Yoアカウントがあるかどうか検証
    # TODO: githubアカウントが実在するかどうか検証
    @sendQuery query, (data) ->
      callback data[0], data[1]
      return

  # Delete data in database
  deleteData: (yo_name, callback = ->) ->
    query = "DELETE FROM #{@db_name} WHERE yo_name='#{yo_name}';"
    @sendQuery query, (data) ->
      callback data[0], data[1]
{'fraction_non_alphanumeric': 0.1317780580075662, 'fraction_numerical': 0.006305170239596469, 'mean_word_length': 2.9076354679802954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '5080447', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1124, 'n_words': 274}