102 lines
2.6 KiB
JavaScript
Raw Normal View History

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
// Redshift Query Builder & Compiler
// ------
import inherits from 'inherits';
import QueryCompiler from '../../../query/compiler';
import QueryCompiler_PG from '../../postgres/query/compiler';
import * as helpers from '../../../helpers';
import { assign, reduce } from 'lodash';
function QueryCompiler_Redshift(client, builder) {
QueryCompiler_PG.call(this, client, builder);
}
inherits(QueryCompiler_Redshift, QueryCompiler_PG);
assign(QueryCompiler_Redshift.prototype, {
truncate() {
return `truncate ${this.tableName.toLowerCase()}`;
},
// Compiles an `insert` query, allowing for multiple
// inserts using a single query statement.
insert() {
const sql = QueryCompiler.prototype.insert.apply(this, arguments);
if (sql === '') return sql;
this._slightReturn();
return {
sql,
};
},
// Compiles an `update` query, warning on unsupported returning
update() {
const sql = QueryCompiler.prototype.update.apply(this, arguments);
this._slightReturn();
return {
sql,
};
},
// Compiles an `delete` query, warning on unsupported returning
del() {
const sql = QueryCompiler.prototype.del.apply(this, arguments);
this._slightReturn();
return {
sql,
};
},
// simple: if trying to return, warn
_slightReturn(){
if (this.single.isReturning) {
helpers.warn('insert/update/delete returning is not supported by redshift dialect');
}
},
forUpdate() {
helpers.warn('table lock is not supported by redshift dialect');
return '';
},
forShare() {
helpers.warn('lock for share is not supported by redshift dialect');
return '';
},
// Compiles a columnInfo query
columnInfo() {
const column = this.single.columnInfo;
let sql = 'select * from information_schema.columns where table_name = ? and table_catalog = ?';
const bindings = [this.single.table.toLowerCase(), this.client.database().toLowerCase()];
if (this.single.schema) {
sql += ' and table_schema = ?';
bindings.push(this.single.schema);
} else {
sql += ' and table_schema = current_schema()';
}
return {
sql,
bindings,
output(resp) {
const out = reduce(resp.rows, function(columns, val) {
columns[val.column_name] = {
type: val.data_type,
maxLength: val.character_maximum_length,
nullable: (val.is_nullable === 'YES'),
defaultValue: val.column_default
};
return columns;
}, {});
return column && out[column] || out;
}
};
}
})
export default QueryCompiler_Redshift;