<commit_before>'use strict';

const types = require('pg').types;
const Select = require('../../lib/statement/select');

describe('query', function () {
  let db;

  before(function () {
    return resetDb('singletable').then(instance => db = instance);
  });

  after(function () {
    return db.instance.$pool.end();
  });

  it('runs raw unparameterized SQL', function () {
    return db.query('select * from products').then(res => {
      assert.equal(4, res.length);
    });
  });

  it('runs a simple prepared statement', function () {
    return db.query('select $1 as val', ['hi']).then(result => assert.equal(result[0].val, 'hi'));
  });

  it('runs a prepared statement without parameters', function () {
    return db.query('select 1 as val').then(result => assert.equal(result[0].val, 1));
  });

  it('runs a prepared statement with empty parameters', function () {
    return db.query('select 1 as val', []).then(result => assert.equal(result[0].val, 1));
  });

  it('runs a prepared statement with undefined parameters', function () {
    return db.query('select 1 as val', undefined).then(result => assert.equal(result[0].val, 1));
  });

  it('runs a parameterized prepared statement with an undefined parameter', function () {
    return db.query('select $1 as val', [undefined]).then(result => assert.isNull(result[0].val));
  });

  it('fails to run a parameterized prepared statement with empty parameters', function () {
    return db.query('select $1 as val', []).then(() => assert.fail()).catch(() => {});
  });

  it('fails to run a parameterized prepared statement with an undefined parameter', function () {
    return db.query('select $1 as val', undefined).then(() => assert.fail()).catch(() => {});
  });

  it('runs a prepared statement using named parameters', function () {<commit_msg>test: validate formatting bypass<commit_after>'use strict';

const types = require('pg').types;
const Select = require('../../lib/statement/select');

describe('query', function () {
  let db;

  before(function () {
    return resetDb('singletable').then(instance => db = instance);
  });

  after(function () {
    return db.instance.$pool.end();
  });

  it('runs raw unparameterized SQL', function () {
    return db.query('select * from products').then(res => {
      assert.equal(4, res.length);
    });
  });

  it('runs a simple prepared statement', function () {
    return db.query('select $1 as val', ['hi']).then(result => assert.equal(result[0].val, 'hi'));
  });

  it('runs a prepared statement without parameters', function () {
    return db.query('select 1 as val').then(result => assert.equal(result[0].val, 1));
  });

  it('runs a prepared statement with empty parameters', function () {
    return db.query('select 1 as val', []).then(result => assert.equal(result[0].val, 1));
  });

  it('runs a prepared statement with undefined parameters', function () {
    return db.query('select 1 as val', undefined).then(result => assert.equal(result[0].val, 1));
  });

  it('runs a parameterized prepared statement with an undefined parameter', function () {
    return db.query('select $1 as val', [undefined]).then(result => assert.isNull(result[0].val));
  });

  it('fails to run a parameterized prepared statement with empty parameters', function () {
    return db.query('select $1 as val', []).then(() => assert.fail()).catch(() => {});
  });

  it('does not apply formatting when not required', function () {
    return db.query('select \'$1\' as val').then(result => assert.equal(result[0].val, '$1'));
  });

  it('runs a prepared statement using named parameters', function () {
{'fraction_non_alphanumeric': 0.184878587196468, 'fraction_numerical': 0.009381898454746136, 'mean_word_length': 4.07703081232493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '2228668', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1029, 'n_words': 305}