{"size": 719, "ext": "js", "max_stars_repo_path": "server/db/db_pool.js", "max_stars_repo_name": "alexmiller522/Truth-Loop", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/db/db_pool.js", "max_issues_repo_name": "alexmiller522/Truth-Loop", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/db/db_pool.js", "max_forks_repo_name": "alexmiller522/Truth-Loop", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.9722222222, "max_line_length": 63, "alphanum_fraction": 0.6995827538}
const Pool = require('pg').Pool
const fs = require('fs')

var dbHost = process.env.DB_HOST || 'localhost'
var dbUserName = process.env.DB_USERNAME || 'NO_SET'
var dbPassword = process.env.DB_PASSWORD || 'NO_SET'
var dbPort = process.env.DB_PORT || 5432
var dbDatabaseName = process.env.DB_DATABASE_NAME || 'policydb'
var dbCertFile = process.env.DB_CERTFILE

let ssl = false
if (dbCertFile) {
  ssl = {
    rejectUnauthorized: false,
    ca: fs.readFileSync(process.env.DB_CERTFILE).toString(),
  }
}

const config = {
  host: dbHost,
  port: dbPort,
  database: dbDatabaseName,
  user: dbUserName,
  password: dbPassword,
}

if (ssl) {
  config.ssl = ssl
}

const pool = new Pool(config)

module.exports = {
  pool,
}
