Add initial version of dijkstra backend cloudron image
This commit is contained in:
73
node_modules/knex/lib/dialects/redshift/index.js
generated
vendored
Normal file
73
node_modules/knex/lib/dialects/redshift/index.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
// Redshift
|
||||
// -------
|
||||
const inherits = require('inherits');
|
||||
const Client_PG = require('../postgres');
|
||||
const { map } = require('lodash');
|
||||
|
||||
const Transaction = require('./transaction');
|
||||
const QueryCompiler = require('./query/compiler');
|
||||
const ColumnBuilder = require('./schema/columnbuilder');
|
||||
const ColumnCompiler = require('./schema/columncompiler');
|
||||
const TableCompiler = require('./schema/tablecompiler');
|
||||
const SchemaCompiler = require('./schema/compiler');
|
||||
|
||||
function Client_Redshift(config) {
|
||||
Client_PG.apply(this, arguments);
|
||||
}
|
||||
inherits(Client_Redshift, Client_PG);
|
||||
|
||||
Object.assign(Client_Redshift.prototype, {
|
||||
transaction() {
|
||||
return new Transaction(this, ...arguments);
|
||||
},
|
||||
|
||||
queryCompiler() {
|
||||
return new QueryCompiler(this, ...arguments);
|
||||
},
|
||||
|
||||
columnBuilder() {
|
||||
return new ColumnBuilder(this, ...arguments);
|
||||
},
|
||||
|
||||
columnCompiler() {
|
||||
return new ColumnCompiler(this, ...arguments);
|
||||
},
|
||||
|
||||
tableCompiler() {
|
||||
return new TableCompiler(this, ...arguments);
|
||||
},
|
||||
|
||||
schemaCompiler() {
|
||||
return new SchemaCompiler(this, ...arguments);
|
||||
},
|
||||
|
||||
dialect: 'redshift',
|
||||
|
||||
driverName: 'pg-redshift',
|
||||
|
||||
_driver() {
|
||||
return require('pg');
|
||||
},
|
||||
|
||||
// Ensures the response is returned in the same format as other clients.
|
||||
processResponse(obj, runner) {
|
||||
const resp = obj.response;
|
||||
if (obj.output) return obj.output.call(runner, resp);
|
||||
if (obj.method === 'raw') return resp;
|
||||
if (resp.command === 'SELECT') {
|
||||
if (obj.method === 'first') return resp.rows[0];
|
||||
if (obj.method === 'pluck') return map(resp.rows, obj.pluck);
|
||||
return resp.rows;
|
||||
}
|
||||
if (
|
||||
resp.command === 'INSERT' ||
|
||||
resp.command === 'UPDATE' ||
|
||||
resp.command === 'DELETE'
|
||||
) {
|
||||
return resp.rowCount;
|
||||
}
|
||||
return resp;
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Client_Redshift;
|
||||
122
node_modules/knex/lib/dialects/redshift/query/compiler.js
generated
vendored
Normal file
122
node_modules/knex/lib/dialects/redshift/query/compiler.js
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
// Redshift Query Builder & Compiler
|
||||
// ------
|
||||
const inherits = require('inherits');
|
||||
|
||||
const QueryCompiler = require('../../../query/compiler');
|
||||
const QueryCompiler_PG = require('../../postgres/query/compiler');
|
||||
|
||||
const { reduce, identity } = require('lodash');
|
||||
|
||||
function QueryCompiler_Redshift(client, builder) {
|
||||
QueryCompiler_PG.call(this, client, builder);
|
||||
}
|
||||
|
||||
inherits(QueryCompiler_Redshift, QueryCompiler_PG);
|
||||
|
||||
Object.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) {
|
||||
this.client.logger.warn(
|
||||
'insert/update/delete returning is not supported by redshift dialect'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
forUpdate() {
|
||||
this.client.logger.warn('table lock is not supported by redshift dialect');
|
||||
return '';
|
||||
},
|
||||
|
||||
forShare() {
|
||||
this.client.logger.warn(
|
||||
'lock for share is not supported by redshift dialect'
|
||||
);
|
||||
return '';
|
||||
},
|
||||
|
||||
// Compiles a columnInfo query
|
||||
columnInfo() {
|
||||
const column = this.single.columnInfo;
|
||||
let schema = this.single.schema;
|
||||
|
||||
// The user may have specified a custom wrapIdentifier function in the config. We
|
||||
// need to run the identifiers through that function, but not format them as
|
||||
// identifiers otherwise.
|
||||
const table = this.client.customWrapIdentifier(this.single.table, identity);
|
||||
|
||||
if (schema) {
|
||||
schema = this.client.customWrapIdentifier(schema, identity);
|
||||
}
|
||||
|
||||
let sql =
|
||||
'select * from information_schema.columns where table_name = ? and table_catalog = ?';
|
||||
const bindings = [
|
||||
table.toLowerCase(),
|
||||
this.client.database().toLowerCase(),
|
||||
];
|
||||
|
||||
if (schema) {
|
||||
sql += ' and table_schema = ?';
|
||||
bindings.push(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;
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = QueryCompiler_Redshift;
|
||||
20
node_modules/knex/lib/dialects/redshift/schema/columnbuilder.js
generated
vendored
Normal file
20
node_modules/knex/lib/dialects/redshift/schema/columnbuilder.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
const inherits = require('inherits');
|
||||
const ColumnBuilder = require('../../../schema/columnbuilder');
|
||||
|
||||
function ColumnBuilder_Redshift() {
|
||||
ColumnBuilder.apply(this, arguments);
|
||||
}
|
||||
inherits(ColumnBuilder_Redshift, ColumnBuilder);
|
||||
|
||||
// primary needs to set not null on non-preexisting columns, or fail
|
||||
ColumnBuilder_Redshift.prototype.primary = function() {
|
||||
this.notNullable();
|
||||
return ColumnBuilder.prototype.primary.apply(this, arguments);
|
||||
};
|
||||
|
||||
ColumnBuilder_Redshift.prototype.index = function() {
|
||||
this.client.logger.warn('Redshift does not support the creation of indexes.');
|
||||
return this;
|
||||
};
|
||||
|
||||
module.exports = ColumnBuilder_Redshift;
|
||||
60
node_modules/knex/lib/dialects/redshift/schema/columncompiler.js
generated
vendored
Normal file
60
node_modules/knex/lib/dialects/redshift/schema/columncompiler.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
// Redshift Column Compiler
|
||||
// -------
|
||||
|
||||
const inherits = require('inherits');
|
||||
const ColumnCompiler_PG = require('../../postgres/schema/columncompiler');
|
||||
|
||||
function ColumnCompiler_Redshift() {
|
||||
ColumnCompiler_PG.apply(this, arguments);
|
||||
}
|
||||
inherits(ColumnCompiler_Redshift, ColumnCompiler_PG);
|
||||
|
||||
Object.assign(ColumnCompiler_Redshift.prototype, {
|
||||
// Types:
|
||||
// ------
|
||||
bigincrements: 'bigint identity(1,1) primary key not null',
|
||||
binary: 'varchar(max)',
|
||||
bit(column) {
|
||||
return column.length !== false ? `char(${column.length})` : 'char(1)';
|
||||
},
|
||||
blob: 'varchar(max)',
|
||||
enu: 'varchar(255)',
|
||||
enum: 'varchar(255)',
|
||||
increments: 'integer identity(1,1) primary key not null',
|
||||
json: 'varchar(max)',
|
||||
jsonb: 'varchar(max)',
|
||||
longblob: 'varchar(max)',
|
||||
mediumblob: 'varchar(16777218)',
|
||||
set: 'text',
|
||||
text: 'varchar(max)',
|
||||
datetime(without) {
|
||||
return without ? 'timestamp' : 'timestamptz';
|
||||
},
|
||||
timestamp(without) {
|
||||
return without ? 'timestamp' : 'timestamptz';
|
||||
},
|
||||
tinyblob: 'varchar(256)',
|
||||
uuid: 'char(36)',
|
||||
varbinary: 'varchar(max)',
|
||||
bigint: 'bigint',
|
||||
bool: 'boolean',
|
||||
double: 'double precision',
|
||||
floating: 'real',
|
||||
smallint: 'smallint',
|
||||
tinyint: 'smallint',
|
||||
|
||||
// Modifiers:
|
||||
// ------
|
||||
comment(comment) {
|
||||
this.pushAdditional(function() {
|
||||
this.pushQuery(
|
||||
`comment on column ${this.tableCompiler.tableName()}.` +
|
||||
this.formatter.wrap(this.args[0]) +
|
||||
' is ' +
|
||||
(comment ? `'${comment}'` : 'NULL')
|
||||
);
|
||||
}, comment);
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = ColumnCompiler_Redshift;
|
||||
14
node_modules/knex/lib/dialects/redshift/schema/compiler.js
generated
vendored
Normal file
14
node_modules/knex/lib/dialects/redshift/schema/compiler.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
// Redshift Table Builder & Compiler
|
||||
// -------
|
||||
|
||||
const inherits = require('inherits');
|
||||
const SchemaCompiler_PG = require('../../postgres/schema/compiler');
|
||||
|
||||
function SchemaCompiler_Redshift() {
|
||||
SchemaCompiler_PG.apply(this, arguments);
|
||||
}
|
||||
inherits(SchemaCompiler_Redshift, SchemaCompiler_PG);
|
||||
|
||||
module.exports = SchemaCompiler_Redshift;
|
||||
123
node_modules/knex/lib/dialects/redshift/schema/tablecompiler.js
generated
vendored
Normal file
123
node_modules/knex/lib/dialects/redshift/schema/tablecompiler.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
/* eslint max-len: 0 */
|
||||
|
||||
// Redshift Table Builder & Compiler
|
||||
// -------
|
||||
|
||||
const inherits = require('inherits');
|
||||
const { has } = require('lodash');
|
||||
const TableCompiler_PG = require('../../postgres/schema/tablecompiler');
|
||||
|
||||
function TableCompiler_Redshift() {
|
||||
TableCompiler_PG.apply(this, arguments);
|
||||
}
|
||||
inherits(TableCompiler_Redshift, TableCompiler_PG);
|
||||
|
||||
TableCompiler_Redshift.prototype.index = function(
|
||||
columns,
|
||||
indexName,
|
||||
indexType
|
||||
) {
|
||||
this.client.logger.warn('Redshift does not support the creation of indexes.');
|
||||
};
|
||||
|
||||
TableCompiler_Redshift.prototype.dropIndex = function(columns, indexName) {
|
||||
this.client.logger.warn('Redshift does not support the deletion of indexes.');
|
||||
};
|
||||
|
||||
// TODO: have to disable setting not null on columns that already exist...
|
||||
|
||||
// Adds the "create" query to the query sequence.
|
||||
TableCompiler_Redshift.prototype.createQuery = function(columns, ifNot) {
|
||||
const createStatement = ifNot
|
||||
? 'create table if not exists '
|
||||
: 'create table ';
|
||||
let sql =
|
||||
createStatement + this.tableName() + ' (' + columns.sql.join(', ') + ')';
|
||||
if (this.single.inherits)
|
||||
sql += ` like (${this.formatter.wrap(this.single.inherits)})`;
|
||||
this.pushQuery({
|
||||
sql,
|
||||
bindings: columns.bindings,
|
||||
});
|
||||
const hasComment = has(this.single, 'comment');
|
||||
if (hasComment) this.comment(this.single.comment);
|
||||
};
|
||||
|
||||
TableCompiler_Redshift.prototype.primary = function(columns, constraintName) {
|
||||
const self = this;
|
||||
constraintName = constraintName
|
||||
? self.formatter.wrap(constraintName)
|
||||
: self.formatter.wrap(`${this.tableNameRaw}_pkey`);
|
||||
if (columns.constructor !== Array) {
|
||||
columns = [columns];
|
||||
}
|
||||
const thiscolumns = self.grouped.columns;
|
||||
|
||||
if (thiscolumns) {
|
||||
for (let i = 0; i < columns.length; i++) {
|
||||
let exists = thiscolumns.find(
|
||||
(tcb) =>
|
||||
tcb.grouping === 'columns' &&
|
||||
tcb.builder &&
|
||||
tcb.builder._method === 'add' &&
|
||||
tcb.builder._args &&
|
||||
tcb.builder._args.indexOf(columns[i]) > -1
|
||||
);
|
||||
if (exists) {
|
||||
exists = exists.builder;
|
||||
}
|
||||
const nullable = !(
|
||||
exists &&
|
||||
exists._modifiers &&
|
||||
exists._modifiers['nullable'] &&
|
||||
exists._modifiers['nullable'][0] === false
|
||||
);
|
||||
if (nullable) {
|
||||
if (exists) {
|
||||
return this.client.logger.warn(
|
||||
'Redshift does not allow primary keys to contain nullable columns.'
|
||||
);
|
||||
} else {
|
||||
return this.client.logger.warn(
|
||||
'Redshift does not allow primary keys to contain nonexistent columns.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return self.pushQuery(
|
||||
`alter table ${self.tableName()} add constraint ${constraintName} primary key (${self.formatter.columnize(
|
||||
columns
|
||||
)})`
|
||||
);
|
||||
};
|
||||
|
||||
// Compiles column add. Redshift can only add one column per ALTER TABLE, so core addColumns doesn't work. #2545
|
||||
TableCompiler_Redshift.prototype.addColumns = function(
|
||||
columns,
|
||||
prefix,
|
||||
colCompilers
|
||||
) {
|
||||
if (prefix === this.alterColumnsPrefix) {
|
||||
TableCompiler_PG.prototype.addColumns.call(
|
||||
this,
|
||||
columns,
|
||||
prefix,
|
||||
colCompilers
|
||||
);
|
||||
} else {
|
||||
prefix = prefix || this.addColumnsPrefix;
|
||||
colCompilers = colCompilers || this.getColumns();
|
||||
for (const col of colCompilers) {
|
||||
const quotedTableName = this.tableName();
|
||||
const colCompiled = col.compileColumn();
|
||||
|
||||
this.pushQuery({
|
||||
sql: `alter table ${quotedTableName} ${prefix}${colCompiled}`,
|
||||
bindings: [],
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = TableCompiler_Redshift;
|
||||
18
node_modules/knex/lib/dialects/redshift/transaction.js
generated
vendored
Normal file
18
node_modules/knex/lib/dialects/redshift/transaction.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
const Transaction = require('../../transaction');
|
||||
|
||||
module.exports = class Redshift_Transaction extends Transaction {
|
||||
savepoint(conn) {
|
||||
this.trxClient.logger('Redshift does not support savepoints.');
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
release(conn, value) {
|
||||
this.trxClient.logger('Redshift does not support savepoints.');
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
rollbackTo(conn, error) {
|
||||
this.trxClient.logger('Redshift does not support savepoints.');
|
||||
return Promise.resolve();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user