<commit_before>'use strict';

var _      = require('lodash');
var assert = require('assert');
var From   = require('../node/from');
var Select = require('../node/select');
var Table  = require('../table');

var Postgres = function(config) {
  this.output = [];
  this.params = [];
  this.config = config || {};
};

Postgres.prototype._myClass = Postgres;

Postgres.prototype._arrayAggFunctionName = 'array_agg';

Postgres.prototype._getParameterText = function(index, value) {
  if (this._disableParameterPlaceholders) {
    // do not use placeholder
    return this._getParameterValue(value);
  } else {
    // use placeholder
    return this._getParameterPlaceholder(index, value);
  }
};

Postgres.prototype._getParameterValue = function(value, quoteChar) {
  // handle primitives
  if (null === value) {
    value = 'NULL';
  } else if ('boolean' === typeof value) {
    value = value ? 'TRUE' : 'FALSE';
  } else if ('number' === typeof value) {
    // number is just number
    value = value;
  } else if ('string' === typeof value) {
    // string uses single quote by default
    value = this.quote(value, quoteChar || "'");
  } else if ('object' === typeof value) {
    if (_.isArray(value)) {
      // convert each element of the array
      value = value.map(function (item) {
          // In a Postgres array, strings must be double-quoted
          return this._getParameterValue(item, '"');
      });
      value = '\'{' + value.join(',') + '}\'';
    } else if (_.isFunction(value.toISOString)) {
      // Date object's default toString format does not get parsed well
      // Handle date like objects using toISOString
      value = this._getParameterValue(value.toISOString());
    } else if (Buffer.isBuffer(value)) {
      value = this._getParameterValue('\\x' + value.toString('hex'));
    } else {
      // rich object represent with string
      value = this._getParameterValue(value.toString());
    }
  } else {
    throw new Error('Unable to use ' + value + ' in query');
  }

  // value has been converted at this point
  return value;
};

Postgres.prototype._getParameterPlaceholder = function(index, value) {
  /* jshint unused: false */<commit_msg>Alias 'this' because we're in a closure<commit_after>'use strict';

var _      = require('lodash');
var assert = require('assert');
var From   = require('../node/from');
var Select = require('../node/select');
var Table  = require('../table');

var Postgres = function(config) {
  this.output = [];
  this.params = [];
  this.config = config || {};
};

Postgres.prototype._myClass = Postgres;

Postgres.prototype._arrayAggFunctionName = 'array_agg';

Postgres.prototype._getParameterText = function(index, value) {
  if (this._disableParameterPlaceholders) {
    // do not use placeholder
    return this._getParameterValue(value);
  } else {
    // use placeholder
    return this._getParameterPlaceholder(index, value);
  }
};

Postgres.prototype._getParameterValue = function(value, quoteChar) {
  // handle primitives
  if (null === value) {
    value = 'NULL';
  } else if ('boolean' === typeof value) {
    value = value ? 'TRUE' : 'FALSE';
  } else if ('number' === typeof value) {
    // number is just number
    value = value;
  } else if ('string' === typeof value) {
    // string uses single quote by default
    value = this.quote(value, quoteChar || "'");
  } else if ('object' === typeof value) {
    if (_.isArray(value)) {
      // convert each element of the array
      var self = this;
      value = value.map(function (item) {
          // In a Postgres array, strings must be double-quoted
          return self._getParameterValue(item, '"');
      });
      value = '\'{' + value.join(',') + '}\'';
    } else if (_.isFunction(value.toISOString)) {
      // Date object's default toString format does not get parsed well
      // Handle date like objects using toISOString
      value = this._getParameterValue(value.toISOString());
    } else if (Buffer.isBuffer(value)) {
      value = this._getParameterValue('\\x' + value.toString('hex'));
    } else {
      // rich object represent with string
      value = this._getParameterValue(value.toString());
    }
  } else {
    throw new Error('Unable to use ' + value + ' in query');
  }

  // value has been converted at this point
  return value;
};

Postgres.prototype._getParameterPlaceholder = function(index, value) {
  /* jshint unused: false */
{'fraction_non_alphanumeric': 0.14778660612939842, 'fraction_numerical': 0.0, 'mean_word_length': 3.0834105653382764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2190944', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1270, 'n_words': 359}