mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
clickhouse - view support, incremental structure update
This commit is contained in:
parent
d2e49967e4
commit
e21c6d4872
@ -33,6 +33,8 @@ class Analyser extends DatabaseAnalyser {
|
||||
const tables = await this.analyserQuery('tables', ['tables']);
|
||||
this.feedback({ analysingMessage: 'Loading columns' });
|
||||
const columns = await this.analyserQuery('columns', ['tables', 'views']);
|
||||
this.feedback({ analysingMessage: 'Loading views' });
|
||||
const views = await this.analyserQuery('views', ['views']);
|
||||
|
||||
const res = {
|
||||
tables: tables.rows.map((table) => ({
|
||||
@ -53,10 +55,29 @@ class Analyser extends DatabaseAnalyser {
|
||||
: null,
|
||||
foreignKeys: [],
|
||||
})),
|
||||
views: views.rows.map((view) => ({
|
||||
...view,
|
||||
columns: columns.rows
|
||||
.filter((col) => col.pureName == view.pureName)
|
||||
.map((col) => ({
|
||||
...col,
|
||||
...extractDataType(col.dataType),
|
||||
})),
|
||||
createSql: `CREATE VIEW "${view.pureName}"\nAS\n${view.viewDefinition}`,
|
||||
})),
|
||||
};
|
||||
this.feedback({ analysingMessage: null });
|
||||
return res;
|
||||
}
|
||||
|
||||
async _getFastSnapshot() {
|
||||
const tableModificationsQueryData = await this.analyserQuery('tableModifications');
|
||||
|
||||
return {
|
||||
tables: tableModificationsQueryData.rows.filter((x) => x.tableEngine != 'View'),
|
||||
views: tableModificationsQueryData.rows.filter((x) => x.tableEngine == 'View'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Analyser;
|
||||
|
@ -1,7 +1,11 @@
|
||||
const columns = require('./columns');
|
||||
const tables = require('./tables');
|
||||
const views = require('./views');
|
||||
const tableModifications = require('./tableModifications');
|
||||
|
||||
module.exports = {
|
||||
columns,
|
||||
tables,
|
||||
views,
|
||||
tableModifications,
|
||||
};
|
||||
|
@ -0,0 +1,5 @@
|
||||
module.exports = `
|
||||
select metadata_modification_time as "contentHash", uuid as "objectId", engine as "tableEngine"
|
||||
from system.tables
|
||||
where database='#DATABASE#';
|
||||
`;
|
@ -2,5 +2,5 @@ module.exports = `
|
||||
select name as "pureName", metadata_modification_time as "contentHash", total_rows as "tableRowCount", uuid as "objectId", comment as "objectComment",
|
||||
engine as "tableEngine", primary_key as "primaryKeyColumns", sorting_key as "sortingKeyColumns"
|
||||
from system.tables
|
||||
where database='#DATABASE#' and uuid =OBJECT_ID_CONDITION;
|
||||
where database='#DATABASE#' and uuid =OBJECT_ID_CONDITION and engine != 'View';
|
||||
`;
|
||||
|
10
plugins/dbgate-plugin-clickhouse/src/backend/sql/views.js
Normal file
10
plugins/dbgate-plugin-clickhouse/src/backend/sql/views.js
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports = `
|
||||
select
|
||||
tables.name as "pureName",
|
||||
tables.uuid as "objectId",
|
||||
views.view_definition as "viewDefinition",
|
||||
tables.metadata_modification_time as "contentHash"
|
||||
from information_schema.views
|
||||
inner join system.tables on views.table_name = tables.name and views.table_schema = tables.database
|
||||
where views.table_schema='#DATABASE#' and tables.uuid =OBJECT_ID_CONDITION
|
||||
`;
|
Loading…
Reference in New Issue
Block a user