mysql - analyse views

This commit is contained in:
Jan Prochazka
2020-06-28 21:19:51 +02:00
parent 4e1ee72d4d
commit a85ad0a1f0
5 changed files with 31 additions and 6 deletions

View File

@@ -62,6 +62,26 @@ class MySqlAnalyser extends DatabaseAnalayser {
return res;
}
getRequestedViewNames(allViewNames) {
if (this.singleObjectFilter) {
const { typeField, pureName } = this.singleObjectFilter;
if (typeField == 'views') return [pureName];
}
if (this.modifications) {
return this.modifications.filter((x) => x.objectTypeField == 'views').map((x) => x.newName);
}
return allViewNames;
}
async getViewTexts(allViewNames) {
const res = {};
for (const viewName of this.getRequestedViewNames(allViewNames)) {
const resp = await this.driver.query(this.pool, `SHOW CREATE VIEW \`${viewName}\``);
res[viewName] = resp.rows[0]['Create View'];
}
return res;
}
async _runAnalysis() {
const tables = await this.driver.query(this.pool, this.createQuery('tables'));
const columns = await this.driver.query(this.pool, this.createQuery('columns'));
@@ -70,6 +90,8 @@ class MySqlAnalyser extends DatabaseAnalayser {
const views = await this.driver.query(this.pool, this.createQuery('views'));
const programmables = await this.driver.query(this.pool, this.createQuery('programmables'));
const viewTexts = await this.getViewTexts(views.rows.map((x) => x.pureName));
return this.mergeAnalyseResult({
tables: tables.rows.map((table) => ({
...table,
@@ -80,6 +102,7 @@ class MySqlAnalyser extends DatabaseAnalayser {
views: views.rows.map((view) => ({
...view,
columns: columns.rows.filter((col) => col.pureName == view.pureName).map(getColumnInfo),
createSql: viewTexts[view.pureName],
})),
procedures: programmables.rows.filter((x) => x.objectType == 'PROCEDURE').map(fp.omit(['objectType'])),
functions: programmables.rows.filter((x) => x.objectType == 'FUNCTION').map(fp.omit(['objectType'])),