mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 18:46:02 +00:00
mysql - analyse views
This commit is contained in:
@@ -97,7 +97,8 @@ class StreamHandler {
|
|||||||
}
|
}
|
||||||
row(row) {
|
row(row) {
|
||||||
// console.log('ACCEPT 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);
|
// this.onRow(this.jslid);
|
||||||
}
|
}
|
||||||
// error(error) {
|
// error(error) {
|
||||||
|
|||||||
@@ -62,6 +62,26 @@ class MySqlAnalyser extends DatabaseAnalayser {
|
|||||||
return res;
|
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() {
|
async _runAnalysis() {
|
||||||
const tables = await this.driver.query(this.pool, this.createQuery('tables'));
|
const tables = await this.driver.query(this.pool, this.createQuery('tables'));
|
||||||
const columns = await this.driver.query(this.pool, this.createQuery('columns'));
|
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 views = await this.driver.query(this.pool, this.createQuery('views'));
|
||||||
const programmables = await this.driver.query(this.pool, this.createQuery('programmables'));
|
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({
|
return this.mergeAnalyseResult({
|
||||||
tables: tables.rows.map((table) => ({
|
tables: tables.rows.map((table) => ({
|
||||||
...table,
|
...table,
|
||||||
@@ -80,6 +102,7 @@ class MySqlAnalyser extends DatabaseAnalayser {
|
|||||||
views: views.rows.map((view) => ({
|
views: views.rows.map((view) => ({
|
||||||
...view,
|
...view,
|
||||||
columns: columns.rows.filter((col) => col.pureName == view.pureName).map(getColumnInfo),
|
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'])),
|
procedures: programmables.rows.filter((x) => x.objectType == 'PROCEDURE').map(fp.omit(['objectType'])),
|
||||||
functions: programmables.rows.filter((x) => x.objectType == 'FUNCTION').map(fp.omit(['objectType'])),
|
functions: programmables.rows.filter((x) => x.objectType == 'FUNCTION').map(fp.omit(['objectType'])),
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ module.exports = `
|
|||||||
select
|
select
|
||||||
ROUTINE_NAME as pureName,
|
ROUTINE_NAME as pureName,
|
||||||
ROUTINE_TYPE as objectType,
|
ROUTINE_TYPE as objectType,
|
||||||
|
LAST_ALTERED as modifyDate,
|
||||||
ROUTINE_DEFINITION as createSql
|
ROUTINE_DEFINITION as createSql
|
||||||
from information_schema.routines
|
from information_schema.routines
|
||||||
where ROUTINE_SCHEMA = '#DATABASE#'
|
where ROUTINE_SCHEMA = '#DATABASE#' and ROUTINE_NAME =[OBJECT_NAME_CONDITION]
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
select
|
||||||
TABLE_NAME as pureName,
|
TABLE_NAME as pureName,
|
||||||
VIEW_DEFINITION as createSql
|
coalesce(UPDATE_TIME, CREATE_TIME) as modifyDate
|
||||||
from information_schema.views
|
from information_schema.tables
|
||||||
where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =[OBJECT_NAME_CONDITION];
|
where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =[OBJECT_NAME_CONDITION] and TABLE_TYPE = 'VIEW';
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function useSqlTemplate(sqlTemplate, props) {
|
|||||||
}
|
}
|
||||||
if (sqlTemplate == 'CREATE OBJECT') {
|
if (sqlTemplate == 'CREATE OBJECT') {
|
||||||
const objectInfo = await getSqlObjectInfo(props);
|
const objectInfo = await getSqlObjectInfo(props);
|
||||||
setSql(objectInfo.createSql);
|
if (objectInfo) setSql(objectInfo.createSql);
|
||||||
}
|
}
|
||||||
if (sqlTemplate == 'EXECUTE PROCEDURE') {
|
if (sqlTemplate == 'EXECUTE PROCEDURE') {
|
||||||
const procedureInfo = await getSqlObjectInfo(props);
|
const procedureInfo = await getSqlObjectInfo(props);
|
||||||
|
|||||||
Reference in New Issue
Block a user