<commit_before>'use strict';

// $ createuser root
// $ psql -U root -d postgres
// > CREATE DATABASE azul_test;
// > \q

if (!/^(1|true)$/i.test(process.env.TEST_POSTGRES || '1')) { return; }

var expect = require('chai').expect;
var path = require('path');
var Database = require('../../../lib/db/database');
var BluebirdPromise = require('bluebird');

var db, connection = {
  adapter: 'pg',
  username: process.env.PG_USER || 'root',
  password: process.env.PG_PASSWORD || '',
  database: process.env.PG_DATABASE || 'azul_test'
};

describe('PostgresQL', function() {
  before(function() { db = Database.create(connection); });
  after(function(done) { db.disconnect().then(done, done); });

  it('executes raw sql', function(done) {
    var queries = [
      'create table azul_raw_sql_test (id serial, name varchar(255))',
      'insert into azul_raw_sql_test (name) values (\'Azul\') returning id',
      'select * from azul_raw_sql_test',
      'drop table azul_raw_sql_test'
    ];
    BluebirdPromise.reduce(queries, function(array, query) {
      return db._adapter.execute(query, [], connection).then(function(result) {
        return array.concat([result]);
      });
    }, [])
    .spread(function(result1, result2, result3, result4) {
      expect(result1).to.eql({ command: 'CREATE', rows: [], fields: [] });
      expect(result2).to.eql({ command: 'INSERT',
        rows: [{ id: 1 }], fields: ['id'] });
      expect(result3).to.eql({ command: 'SELECT',
        rows: [{ id: 1, name: 'Azul' }],
        fields: ['id', 'name'] });
      expect(result4).to.eql({ command: 'DROP', rows: [], fields: [] });
    })
    .done(done, done);
  });

  it('receives rows from raw sql', function(done) {
    var query = 'SELECT $1::int AS number';
    var args = ['1'];
    db._adapter.execute(query, args, connection)
    .then(function(result) {
      expect(result.rows).to.eql([{ number: 1 }]);
    })
    .done(done, done);
  });

  describe('with migrations applied', function() {
    before(function(done) {<commit_msg>Case change.<commit_after>'use strict';

// $ createuser root
// $ psql -U root -d postgres
// > CREATE DATABASE azul_test;
// > \q

if (!/^(1|true)$/i.test(process.env.TEST_POSTGRES || '1')) { return; }

var expect = require('chai').expect;
var path = require('path');
var Database = require('../../../lib/db/database');
var BluebirdPromise = require('bluebird');

var db, connection = {
  adapter: 'pg',
  username: process.env.PG_USER || 'root',
  password: process.env.PG_PASSWORD || '',
  database: process.env.PG_DATABASE || 'azul_test'
};

describe('PostgresQL', function() {
  before(function() { db = Database.create(connection); });
  after(function(done) { db.disconnect().then(done, done); });

  it('executes raw sql', function(done) {
    var queries = [
      'CREATE TABLE azul_raw_sql_test (id serial, name varchar(255))',
      'INSERT INTO azul_raw_sql_test (name) VALUES (\'Azul\') RETURNING id',
      'SELECT * FROM azul_raw_sql_test',
      'DROP TABLE azul_raw_sql_test'
    ];
    BluebirdPromise.reduce(queries, function(array, query) {
      return db._adapter.execute(query, [], connection).then(function(result) {
        return array.concat([result]);
      });
    }, [])
    .spread(function(result1, result2, result3, result4) {
      expect(result1).to.eql({ command: 'CREATE', rows: [], fields: [] });
      expect(result2).to.eql({ command: 'INSERT',
        rows: [{ id: 1 }], fields: ['id'] });
      expect(result3).to.eql({ command: 'SELECT',
        rows: [{ id: 1, name: 'Azul' }],
        fields: ['id', 'name'] });
      expect(result4).to.eql({ command: 'DROP', rows: [], fields: [] });
    })
    .done(done, done);
  });

  it('receives rows from raw sql', function(done) {
    var query = 'SELECT $1::int AS number';
    var args = ['1'];
    db._adapter.execute(query, args, connection)
    .then(function(result) {
      expect(result.rows).to.eql([{ number: 1 }]);
    })
    .done(done, done);
  });

  describe('with migrations applied', function() {
    before(function(done) {
{'fraction_non_alphanumeric': 0.19517597834112724, 'fraction_numerical': 0.008860447944868325, 'mean_word_length': 3.441530054644809, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5193745', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1356, 'n_words': 299}