knex/test/integration/builder/aggregate.js

462 lines
12 KiB
JavaScript
Raw Normal View History

/*global describe, it*/
'use strict';
module.exports = function(knex) {
2013-09-12 13:30:47 -04:00
describe('Aggregate', function() {
it('has a sum', function() {
2015-04-28 23:32:41 -04:00
return knex('accounts').sum('logins').testSql(function(tester) {
2013-12-27 14:44:21 -05:00
tester(
'mysql',
'select sum(`logins`) from `accounts`',
[],
[{
'sum(`logins`)': 10
}]
);
tester(
'mysql2',
'select sum(`logins`) from `accounts`',
[],
[{
'sum(`logins`)': '10'
}]
);
2013-12-27 14:44:21 -05:00
tester(
'pg',
2013-12-27 14:44:21 -05:00
'select sum("logins") from "accounts"',
[],
[{
sum: '10'
}]
);
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
tester(
'pg-redshift',
'select sum("logins") from "accounts"',
[],
[{
sum: '10'
}]
);
2013-12-27 14:44:21 -05:00
tester(
'sqlite3',
'select sum(`logins`) from `accounts`',
2013-12-27 14:44:21 -05:00
[],
[{
'sum(`logins`)': 10
2013-12-27 14:44:21 -05:00
}]
);
tester(
'oracledb',
'select sum("logins") from "accounts"',
[],
[{
'SUM("LOGINS")': 10
}]
);
tester(
'mssql',
'select sum([logins]) from [accounts]',
[],
[{
'': 10
}]
);
2013-12-27 14:44:21 -05:00
});
});
it('has an avg', function() {
2014-04-16 02:50:19 -04:00
return knex('accounts').avg('logins').testSql(function(tester) {
function checkResRange(key, resp) {
return Math.abs(10/6 - +(resp[0][key])) < 0.001;
}
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
function checkResRangeMssql(key, resp) {
return +(resp[0][key]) === 1;
}
// mysql: 1.6667
tester('mysql', 'select avg(`logins`) from `accounts`', [], checkResRange.bind(null, 'avg(`logins`)'));
// sqlite: 1.6666666666666667
tester('sqlite3', 'select avg(`logins`) from `accounts`', [], checkResRange.bind(null, 'avg(`logins`)'));
// pg: '1.6666666666666667'
tester('pg', 'select avg("logins") from "accounts"', [], checkResRange.bind(null, 'avg'));
// pg-redshift: '1.6666666666666667'
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
tester('pg-redshift', 'select avg("logins") from "accounts"', [], checkResRangeMssql.bind(null, 'avg'));
// oracle: 1.66666666666667
tester('oracledb', 'select avg("logins") from "accounts"', [], checkResRange.bind(null, 'AVG("LOGINS")'));
// mssql: 1
tester('mssql', 'select avg([logins]) from [accounts]', [], checkResRangeMssql.bind(null, ''));
2014-04-16 02:50:19 -04:00
});
});
it('has a count', function() {
2013-12-27 14:44:21 -05:00
return knex('accounts').count('id').testSql(function(tester) {
tester(
2013-12-27 14:44:21 -05:00
'mysql',
'select count(`id`) from `accounts`',
[],
[{
'count(`id`)': 6
}]
);
tester(
'pg',
2013-12-27 14:44:21 -05:00
'select count("id") from "accounts"',
[],
[{
count: '6'
}]
);
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
tester(
'pg-redshift',
'select count("id") from "accounts"',
[],
[{
count: '6'
}]
);
2013-12-27 14:44:21 -05:00
tester(
'sqlite3',
'select count(`id`) from `accounts`',
2013-12-27 14:44:21 -05:00
[],
[{
'count(`id`)': 6
2013-12-27 14:44:21 -05:00
}]
);
tester(
'oracledb',
'select count("id") from "accounts"',
[],
[{
'COUNT("ID")': 6
}]
);
tester(
'mssql',
'select count([id]) from [accounts]',
[],
[{
'': 6
}]
);
2013-12-27 14:44:21 -05:00
});
});
2013-11-23 12:10:01 -05:00
it('supports multiple aggregate functions', function() {
2013-12-27 14:44:21 -05:00
return knex('accounts').count('id').max('logins').min('logins').testSql(function(tester) {
tester(
'mysql',
'select count(`id`), max(`logins`), min(`logins`) from `accounts`',
[],
[{
'count(`id`)': 6,
'max(`logins`)': 2,
'min(`logins`)': 1
}]
);
tester(
'pg',
2013-12-27 14:44:21 -05:00
'select count("id"), max("logins"), min("logins") from "accounts"',
[],
[{
count: '6',
max: 2,
min: 1
}]
);
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
tester(
'pg-redshift',
'select count("id"), max("logins"), min("logins") from "accounts"',
[],
[{
count: '6',
max: 2,
min: 1
}]
);
2013-12-27 14:44:21 -05:00
tester(
'sqlite3',
'select count(`id`), max(`logins`), min(`logins`) from `accounts`',
2013-12-27 14:44:21 -05:00
[],
[{
'count(`id`)': 6,
'max(`logins`)': 2,
'min(`logins`)': 1
2013-12-27 14:44:21 -05:00
}]
);
tester(
'oracledb',
'select count("id"), max("logins"), min("logins") from "accounts"',
[],
[{
'COUNT("ID")': 6,
'MAX("LOGINS")': 2,
'MIN("LOGINS")': 1
}]
);
tester(
'mssql',
'select count([id]), max([logins]), min([logins]) from [accounts]',
[],
[{
'': [6, 2, 1]
}]
);
});
});
it('has distinct modifier for aggregates', function() {
return knex('accounts').countDistinct('id').sumDistinct('logins').avgDistinct('logins').testSql(function(tester) {
tester(
'mysql',
'select count(distinct `id`), sum(distinct `logins`), avg(distinct `logins`) from `accounts`',
[],
[{
'count(distinct `id`)': 6,
'sum(distinct `logins`)': 3,
'avg(distinct `logins`)': 1.5
}]
);
tester(
'pg',
'select count(distinct "id"), sum(distinct "logins"), avg(distinct "logins") from "accounts"',
[],
[{
count: '6',
sum: "3",
avg: "1.5000000000000000"
}]
);
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
tester(
'pg-redshift',
'select count(distinct "id"), sum(distinct "logins"), avg(distinct "logins") from "accounts"',
[],
[{
count: '6',
sum: '3',
avg: '1'
}]
);
tester(
'sqlite3',
'select count(distinct `id`), sum(distinct `logins`), avg(distinct `logins`) from `accounts`',
[],
[{
'count(distinct `id`)': 6,
'sum(distinct `logins`)': 3,
'avg(distinct `logins`)': 1.5
}]
);
tester(
'oracledb',
'select count(distinct "id"), sum(distinct "logins"), avg(distinct "logins") from "accounts"',
[],
[{
'COUNT(DISTINCT"ID")': 6,
'SUM(DISTINCT"LOGINS")': 3,
'AVG(DISTINCT"LOGINS")': 1.5
}]
);
tester(
'mssql',
'select count(distinct [id]), sum(distinct [logins]), avg(distinct [logins]) from [accounts]',
[],
[{
'': [6, 3, 1]
}]
);
2013-12-27 14:44:21 -05:00
});
2013-11-23 12:10:01 -05:00
});
const testWithMultipleColumns = knex.client.driverName === 'mysql' ||
knex.client.driverName === 'pg';
it('supports countDistinct with multiple columns', function() {
if (!testWithMultipleColumns) {
return this.skip();
}
return knex('accounts').countDistinct('id', 'logins').testSql(function(tester) {
tester(
'mysql',
'select count(distinct `id`, `logins`) from `accounts`',
[],
[{
'count(distinct `id`, `logins`)': 6
}]
);
tester(
'pg',
'select count(distinct("id", "logins")) from "accounts"',
[],
[{
count: '6'
}]
);
});
});
it('supports countDistinct with multiple columns with alias', function () {
if (!testWithMultipleColumns) {
return this.skip();
}
return knex('accounts').countDistinct({ count: ['id', 'logins'] })
.testSql(function (tester) {
tester(
'mysql',
'select count(distinct `id`, `logins`) as `count` from `accounts`',
[],
[{
count: 6
}]
);
tester(
'pg',
'select count(distinct("id", "logins")) as "count" from "accounts"',
[],
[{
count: '6'
}]
);
});
});
it("support the groupBy function", function() {
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
return knex('accounts').count('id').groupBy('logins').orderBy('logins', 'asc').testSql(function(tester) {
2013-12-27 14:44:21 -05:00
tester(
'mysql',
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
'select count(`id`) from `accounts` group by `logins` order by `logins` asc',
2013-12-27 14:44:21 -05:00
[],
[{
'count(`id`)': 2
},{
'count(`id`)': 4
}]
);
tester(
'pg',
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
'select count("id") from "accounts" group by "logins" order by "logins" asc',
[],
[{
count: '2'
},{
count: '4'
}]
);
tester(
'pg-redshift',
'select count("id") from "accounts" group by "logins" order by "logins" asc',
2013-12-27 14:44:21 -05:00
[],
[{
count: '2'
},{
count: '4'
}]
);
tester(
'sqlite3',
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
'select count(`id`) from `accounts` group by `logins` order by `logins` asc',
2013-12-27 14:44:21 -05:00
[],
[{
'count(`id`)': 2
2013-12-27 14:44:21 -05:00
},{
'count(`id`)': 4
2013-12-27 14:44:21 -05:00
}]
);
tester(
'oracledb',
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
'select count("id") from "accounts" group by "logins" order by "logins" asc',
[],
[{
'COUNT("ID")': 2
},{
'COUNT("ID")': 4
}]
);
tester(
'mssql',
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
'select count([id]) from [accounts] group by [logins] order by [logins] asc',
[],
[{
'': 2
},{
'': 4
}]
);
2013-12-27 14:44:21 -05:00
}).then(function() {
return knex('accounts').count('id').groupBy('first_name').testSql(function(tester) {
tester(
'mysql',
'select count(`id`) from `accounts` group by `first_name`',
[],
[{
'count(`id`)': 6
}]
);
tester(
'pg',
2013-12-27 14:44:21 -05:00
'select count("id") from "accounts" group by "first_name"',
[],
[{
count: '6'
}]
);
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
tester(
'pg-redshift',
'select count("id") from "accounts" group by "first_name"',
[],
[{
count: '6'
}]
);
2013-12-27 14:44:21 -05:00
tester(
'sqlite3',
'select count(`id`) from `accounts` group by `first_name`',
2013-12-27 14:44:21 -05:00
[],
[{
'count(`id`)': 6
2013-12-27 14:44:21 -05:00
}]
);
tester(
'oracledb',
'select count("id") from "accounts" group by "first_name"',
[],
[{
'COUNT("ID")': 6
}]
);
tester(
'mssql',
'select count([id]) from [accounts] group by [first_name]',
[],
[{
'': 6
}]
);
});
});
});
});
};