mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 01:06:01 +00:00
feat: add parameters to mysql
This commit is contained in:
@@ -60,6 +60,18 @@ function getColumnInfo(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getParametersSqlString(parameters = []) {
|
||||||
|
if (!parameters?.length) return '';
|
||||||
|
|
||||||
|
return parameters
|
||||||
|
.map(i => {
|
||||||
|
const mode = i.parameterMode ? `${i.parameterMode} ` : '';
|
||||||
|
const dataType = i.dataType ? ` ${i.dataType.toUpperCase()}` : '';
|
||||||
|
return mode + i.parameterName + dataType;
|
||||||
|
})
|
||||||
|
.join(', ');
|
||||||
|
}
|
||||||
|
|
||||||
class Analyser extends DatabaseAnalyser {
|
class Analyser extends DatabaseAnalyser {
|
||||||
constructor(dbhan, driver, version) {
|
constructor(dbhan, driver, version) {
|
||||||
super(dbhan, driver, version);
|
super(dbhan, driver, version);
|
||||||
@@ -114,6 +126,24 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
this.feedback({ analysingMessage: 'Loading programmables' });
|
this.feedback({ analysingMessage: 'Loading programmables' });
|
||||||
const programmables = await this.analyserQuery('programmables', ['procedures', 'functions']);
|
const programmables = await this.analyserQuery('programmables', ['procedures', 'functions']);
|
||||||
|
|
||||||
|
const parameters = await this.analyserQuery('parameters', ['procedures', 'functions']);
|
||||||
|
|
||||||
|
const functionParameters = parameters.rows.filter(x => x.routineType == 'FUNCTION');
|
||||||
|
const functionNameToParameters = functionParameters.reduce((acc, row) => {
|
||||||
|
if (!acc[row.pureName]) acc[row.pureName] = [];
|
||||||
|
|
||||||
|
acc[row.pureName].push(row);
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const procedureParameters = parameters.rows.filter(x => x.routineType == 'PROCEDURE');
|
||||||
|
const procedureNameToParameters = procedureParameters.reduce((acc, row) => {
|
||||||
|
if (!acc[row.pureName]) acc[row.pureName] = [];
|
||||||
|
|
||||||
|
acc[row.pureName].push(row);
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading view texts' });
|
this.feedback({ analysingMessage: 'Loading view texts' });
|
||||||
const viewTexts = await this.getViewTexts(views.rows.map(x => x.pureName));
|
const viewTexts = await this.getViewTexts(views.rows.map(x => x.pureName));
|
||||||
this.feedback({ analysingMessage: 'Loading indexes' });
|
this.feedback({ analysingMessage: 'Loading indexes' });
|
||||||
@@ -174,20 +204,26 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
.map(x => _.omit(x, ['objectType']))
|
.map(x => _.omit(x, ['objectType']))
|
||||||
.map(x => ({
|
.map(x => ({
|
||||||
...x,
|
...x,
|
||||||
createSql: `DELIMITER //\n\nCREATE PROCEDURE \`${x.pureName}\`()\n${x.routineDefinition}\n\nDELIMITER ;\n`,
|
createSql: `DELIMITER //\n\nCREATE PROCEDURE \`${x.pureName}\`(${getParametersSqlString(
|
||||||
|
procedureNameToParameters[x.pureName]
|
||||||
|
)})\n${x.routineDefinition}\n\nDELIMITER ;\n`,
|
||||||
objectId: x.pureName,
|
objectId: x.pureName,
|
||||||
contentHash: _.isDate(x.modifyDate) ? x.modifyDate.toISOString() : x.modifyDate,
|
contentHash: _.isDate(x.modifyDate) ? x.modifyDate.toISOString() : x.modifyDate,
|
||||||
|
parameters: procedureNameToParameters[x.pureName],
|
||||||
})),
|
})),
|
||||||
functions: programmables.rows
|
functions: programmables.rows
|
||||||
.filter(x => x.objectType == 'FUNCTION')
|
.filter(x => x.objectType == 'FUNCTION')
|
||||||
.map(x => _.omit(x, ['objectType']))
|
.map(x => _.omit(x, ['objectType']))
|
||||||
.map(x => ({
|
.map(x => ({
|
||||||
...x,
|
...x,
|
||||||
createSql: `CREATE FUNCTION \`${x.pureName}\`()\nRETURNS ${x.returnDataType} ${
|
createSql: `CREATE FUNCTION \`${x.pureName}\`(${getParametersSqlString(
|
||||||
x.isDeterministic == 'YES' ? 'DETERMINISTIC' : 'NOT DETERMINISTIC'
|
functionNameToParameters[x.pureName].filter(i => i.parameterMode !== 'RETURN')
|
||||||
}\n${x.routineDefinition}`,
|
)})\nRETURNS ${x.returnDataType} ${x.isDeterministic == 'YES' ? 'DETERMINISTIC' : 'NOT DETERMINISTIC'}\n${
|
||||||
|
x.routineDefinition
|
||||||
|
}`,
|
||||||
objectId: x.pureName,
|
objectId: x.pureName,
|
||||||
contentHash: _.isDate(x.modifyDate) ? x.modifyDate.toISOString() : x.modifyDate,
|
contentHash: _.isDate(x.modifyDate) ? x.modifyDate.toISOString() : x.modifyDate,
|
||||||
|
parameters: functionNameToParameters[x.pureName],
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
this.feedback({ analysingMessage: null });
|
this.feedback({ analysingMessage: null });
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const procedureModifications = require('./procedureModifications');
|
|||||||
const functionModifications = require('./functionModifications');
|
const functionModifications = require('./functionModifications');
|
||||||
const uniqueNames = require('./uniqueNames');
|
const uniqueNames = require('./uniqueNames');
|
||||||
const viewTexts = require('./viewTexts');
|
const viewTexts = require('./viewTexts');
|
||||||
|
const parameters = require('./parameters');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
columns,
|
columns,
|
||||||
@@ -19,6 +20,7 @@ module.exports = {
|
|||||||
tableModifications,
|
tableModifications,
|
||||||
views,
|
views,
|
||||||
programmables,
|
programmables,
|
||||||
|
parameters,
|
||||||
procedureModifications,
|
procedureModifications,
|
||||||
functionModifications,
|
functionModifications,
|
||||||
indexes,
|
indexes,
|
||||||
|
|||||||
22
plugins/dbgate-plugin-mysql/src/backend/sql/parameters.js
Normal file
22
plugins/dbgate-plugin-mysql/src/backend/sql/parameters.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
module.exports = `
|
||||||
|
SELECT
|
||||||
|
r.SPECIFIC_NAME AS pureName,
|
||||||
|
CASE
|
||||||
|
WHEN COALESCE(NULLIF(PARAMETER_MODE, ''), 'RETURN') = 'RETURN' THEN 'Return'
|
||||||
|
ELSE PARAMETER_NAME
|
||||||
|
END AS parameterName,
|
||||||
|
p.CHARACTER_MAXIMUM_LENGTH AS charMaxLength,
|
||||||
|
p.NUMERIC_PRECISION AS numericPrecision,
|
||||||
|
p.NUMERIC_SCALE AS numericScale,
|
||||||
|
p.DTD_IDENTIFIER AS dataType,
|
||||||
|
COALESCE(NULLIF(PARAMETER_MODE, ''), 'RETURN') AS parameterMode,
|
||||||
|
r.ROUTINE_TYPE AS routineType -- Function or Procedure
|
||||||
|
FROM
|
||||||
|
information_schema.PARAMETERS p
|
||||||
|
JOIN
|
||||||
|
information_schema.ROUTINES r
|
||||||
|
ON
|
||||||
|
p.SPECIFIC_NAME = r.SPECIFIC_NAME
|
||||||
|
WHERE
|
||||||
|
r.ROUTINE_SCHEMA = '#DATABASE#' AND r.ROUTINE_NAME =OBJECT_ID_CONDITION
|
||||||
|
`;
|
||||||
Reference in New Issue
Block a user