<commit_before>/*
 * db-pool
 * https://github.com/mark/node-db-pool
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

var anydb = require('any-db');
var path = require('path');
var conns;
// Keep a reference to created pools for cleanup
var pools = exports.pools = [];

var defaults = {
  postgres: {
    host: "localhost",
    driver: "postgres",
    port: 5432,
    min: 5,
    max: 15
  }
};

// Load config file
var config = exports.config = function (filename) {
  filename = path.join(process.cwd(), filename || 'config/database.js');
  try {
    conns = require(filename);
  } catch (err) {
    console.log('Does ' + filename + ' exist, and does it look similar to config/database.js.sample?');
    throw (err);
  }
};

exports.debug = function debug() {
  return conns;
};

// Build a connection string from target db + env hash
function connStr(db, env) {
  var conn = conns[db][env];
  var userDefaults = conns[db].defaults || {};

  console.log(db, env, userDefaults);

  // Merge default connection values
  Object.keys(defaults[userDefaults.driver]).forEach(function (key) {
    console.log(key);
    conn[key] = conn[key] || userDefaults[key] || defaults[userDefaults.driver][key];
  });
  var connString = conn.driver + '://' + conn.username + (conn.password ? ':' + conn.password : '') + '@' + conn.host
    + (conn.port ? ':' + conn.port : '') + '/' + conn.database;
  return connString;
}

// Create the connection pool via any-db
function createPool(db, env) {
  var conn = conns[db][env];
  conn.connStr = connStr(db, env);
  conn.pool = anydb.createPool(conn.connStr, {
    min: conn.min,
    max: conn.max,
    onConnect: function (conn, done) {
      done(null, conn);
    },
    reset: function (conn, done) {
      done(null);
    }
  });<commit_msg>Added default keys username, password, database as undefined<commit_after>/*
 * db-pool
 * https://github.com/mark/node-db-pool
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

var anydb = require('any-db');
var path = require('path');
var conns;
// Keep a reference to created pools for cleanup
var pools = exports.pools = [];

var defaults = {
  postgres: {
    database: undefined,
    username: undefined,
    password: <PASSWORD>,
    host: "localhost",
    driver: "postgres",
    port: 5432,
    min: 5,
    max: 15
  }
};

// Load config file
var config = exports.config = function (filename) {
  filename = path.join(process.cwd(), filename || 'config/database.js');
  try {
    conns = require(filename);
  } catch (err) {
    console.log('Does ' + filename + ' exist, and does it look similar to config/database.js.sample?');
    throw (err);
  }
};

exports.debug = function debug() {
  return conns;
};

// Build a connection string from target db + env hash
function connStr(db, env) {
  var conn = conns[db][env];
  var userDefaults = conns[db].defaults || {};

  console.log(db, env, userDefaults);

  // Merge default connection values
  Object.keys(defaults[userDefaults.driver]).forEach(function (key) {
    console.log(key);
    conn[key] = conn[key] || userDefaults[key] || defaults[userDefaults.driver][key];
  });
  console.log();
  var connString = conn.driver + '://' + conn.username + (conn.password ? ':' + conn.password : '') + '@' + conn.host
    + (conn.port ? ':' + conn.port : '') + '/' + conn.database;
  return connString;
}

// Create the connection pool via any-db
function createPool(db, env) {
  var conn = conns[db][env];
  conn.connStr = connStr(db, env);
  conn.pool = anydb.createPool(conn.connStr, {
    min: conn.min,
    max: conn.max,
    onConnect: function (conn, done) {
      done(null, conn);
    },
    reset: function (conn, done) {
      done(null);
    }
  });
{'fraction_non_alphanumeric': 0.1646309081253319, 'fraction_numerical': 0.005841741901221455, 'mean_word_length': 3.2421171171171173, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '862660', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1229, 'n_words': 326}