mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 17:16:01 +00:00
clickhouse plugin - initial import
This commit is contained in:
37
plugins/dbgate-plugin-clickhouse/src/backend/Analyser.js
Normal file
37
plugins/dbgate-plugin-clickhouse/src/backend/Analyser.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const { DatabaseAnalyser } = require('dbgate-tools');
|
||||
const sql = require('./sql');
|
||||
|
||||
class Analyser extends DatabaseAnalyser {
|
||||
constructor(connection, driver) {
|
||||
super(connection, driver);
|
||||
}
|
||||
|
||||
createQuery(resFileName, typeFields, replacements = {}) {
|
||||
let res = sql[resFileName];
|
||||
res = res.replace('#DATABASE#', this.pool._database_name);
|
||||
return super.createQuery(res, typeFields, replacements);
|
||||
}
|
||||
|
||||
async _runAnalysis() {
|
||||
this.feedback({ analysingMessage: 'Loading tables' });
|
||||
const tables = await this.analyserQuery('tables', ['tables']);
|
||||
this.feedback({ analysingMessage: 'Loading columns' });
|
||||
const columns = await this.analyserQuery('columns', ['tables', 'views']);
|
||||
|
||||
const res = {
|
||||
tables: tables.rows.map((table) => ({
|
||||
...table,
|
||||
primaryKeyColumns: undefined,
|
||||
sortingKeyColumns: undefined,
|
||||
columns: columns.rows.filter((col) => col.pureName == table.pureName),
|
||||
primaryKey: (table.primaryKeyColumns || '').split(',').map((columnName) => ({ columnName })),
|
||||
sortingKey: (table.sortingKeyColumns || '').split(',').map((columnName) => ({ columnName })),
|
||||
foreignKeys: [],
|
||||
})),
|
||||
};
|
||||
this.feedback({ analysingMessage: null });
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Analyser;
|
||||
Reference in New Issue
Block a user