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

@@ -97,7 +97,8 @@ class StreamHandler {
}
row(row) {
// console.log('ACCEPT ROW', row);
this.currentWriter.row(row);
if (this.currentWriter) this.currentWriter.row(row);
else if (row.message) process.send({ msgtype: 'info', info: { message: row.message } });
// this.onRow(this.jslid);
}
// error(error) {

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'])),

View File

@@ -2,7 +2,8 @@ module.exports = `
select
ROUTINE_NAME as pureName,
ROUTINE_TYPE as objectType,
LAST_ALTERED as modifyDate,
ROUTINE_DEFINITION as createSql
from information_schema.routines
where ROUTINE_SCHEMA = '#DATABASE#'
where ROUTINE_SCHEMA = '#DATABASE#' and ROUTINE_NAME =[OBJECT_NAME_CONDITION]
`;

View File

@@ -1,7 +1,7 @@
module.exports = `
select
TABLE_NAME as pureName,
VIEW_DEFINITION as createSql
from information_schema.views
where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =[OBJECT_NAME_CONDITION];
coalesce(UPDATE_TIME, CREATE_TIME) as modifyDate
from information_schema.tables
where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =[OBJECT_NAME_CONDITION] and TABLE_TYPE = 'VIEW';
`;

View File

@@ -39,7 +39,7 @@ function useSqlTemplate(sqlTemplate, props) {
}
if (sqlTemplate == 'CREATE OBJECT') {
const objectInfo = await getSqlObjectInfo(props);
setSql(objectInfo.createSql);
if (objectInfo) setSql(objectInfo.createSql);
}
if (sqlTemplate == 'EXECUTE PROCEDURE') {
const procedureInfo = await getSqlObjectInfo(props);