mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 06:06:00 +00:00
feat: stored procedures and funciton parameters support for pssql
This commit is contained in:
1
packages/types/dbinfo.d.ts
vendored
1
packages/types/dbinfo.d.ts
vendored
@@ -121,6 +121,7 @@ export interface ViewInfo extends SqlObjectInfo {
|
|||||||
export interface ParameterInfo {
|
export interface ParameterInfo {
|
||||||
objectId?: string | number;
|
objectId?: string | number;
|
||||||
parentObjectId?: string | number;
|
parentObjectId?: string | number;
|
||||||
|
routineName?: string;
|
||||||
pureName: string;
|
pureName: string;
|
||||||
dataType: string;
|
dataType: string;
|
||||||
fullDataType: string;
|
fullDataType: string;
|
||||||
|
|||||||
@@ -144,6 +144,8 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
this.feedback({ analysingMessage: 'Loading routines' });
|
this.feedback({ analysingMessage: 'Loading routines' });
|
||||||
const routines = await this.analyserQuery('routines', ['procedures', 'functions']);
|
const routines = await this.analyserQuery('routines', ['procedures', 'functions']);
|
||||||
|
|
||||||
|
const routineParametersRows = await this.analyserQuery('proceduresParameters');
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading indexes' });
|
this.feedback({ analysingMessage: 'Loading indexes' });
|
||||||
const indexes = this.driver.__analyserInternals.skipIndexes
|
const indexes = this.driver.__analyserInternals.skipIndexes
|
||||||
? { rows: [] }
|
? { rows: [] }
|
||||||
@@ -191,6 +193,42 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
columnName: x.column_name,
|
columnName: x.column_name,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const procedurePerameters = routineParametersRows.rows
|
||||||
|
.filter(i => i.routine_type == 'PROCEDURE')
|
||||||
|
.map(i => ({
|
||||||
|
objectId: 'procedures:' + i.specific_schema + '.' + i.routine_name + '@' + i.pure_name,
|
||||||
|
routineName: i.routine_name,
|
||||||
|
pureName: i.pure_name,
|
||||||
|
dataType: i.data_type,
|
||||||
|
fullDataType: i.data_type,
|
||||||
|
isOutputParameter: i.is_output_parameter,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const procedureNameToParameters = procedurePerameters.reduce((acc, row) => {
|
||||||
|
if (!acc[row.routineName]) acc[row.routineName] = [];
|
||||||
|
acc[row.routineName].push(row);
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const fucntionPerameters = routineParametersRows.rows
|
||||||
|
.filter(i => i.routine_type == 'FUNCTION')
|
||||||
|
.map(i => ({
|
||||||
|
objectId: 'functions:' + i.specific_schema + '.' + i.routine_name + '@' + i.pure_name,
|
||||||
|
routineName: i.routine_name,
|
||||||
|
pureName: i.pure_name,
|
||||||
|
dataType: i.data_type,
|
||||||
|
fullDataType: i.data_type,
|
||||||
|
isOutputParameter: i.is_output_parameter,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const functionNameToParameters = fucntionPerameters.reduce((acc, row) => {
|
||||||
|
if (!acc[row.routineName]) acc[row.routineName] = [];
|
||||||
|
acc[row.routineName].push(row);
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
const res = {
|
const res = {
|
||||||
tables: tables.rows.map(table => {
|
tables: tables.rows.map(table => {
|
||||||
const newTable = {
|
const newTable = {
|
||||||
@@ -281,6 +319,7 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
schemaName: proc.schema_name,
|
schemaName: proc.schema_name,
|
||||||
createSql: `CREATE PROCEDURE "${proc.schema_name}"."${proc.pure_name}"() LANGUAGE ${proc.language}\nAS\n$$\n${proc.definition}\n$$`,
|
createSql: `CREATE PROCEDURE "${proc.schema_name}"."${proc.pure_name}"() LANGUAGE ${proc.language}\nAS\n$$\n${proc.definition}\n$$`,
|
||||||
contentHash: proc.hash_code,
|
contentHash: proc.hash_code,
|
||||||
|
parameters: procedureNameToParameters[proc.pure_name],
|
||||||
})),
|
})),
|
||||||
functions: routines.rows
|
functions: routines.rows
|
||||||
.filter(x => x.object_type == 'FUNCTION')
|
.filter(x => x.object_type == 'FUNCTION')
|
||||||
@@ -290,6 +329,7 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
pureName: func.pure_name,
|
pureName: func.pure_name,
|
||||||
schemaName: func.schema_name,
|
schemaName: func.schema_name,
|
||||||
contentHash: func.hash_code,
|
contentHash: func.hash_code,
|
||||||
|
parameters: functionNameToParameters[func.pure_name],
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const indexcols = require('./indexcols');
|
|||||||
const uniqueNames = require('./uniqueNames');
|
const uniqueNames = require('./uniqueNames');
|
||||||
const geometryColumns = require('./geometryColumns');
|
const geometryColumns = require('./geometryColumns');
|
||||||
const geographyColumns = require('./geographyColumns');
|
const geographyColumns = require('./geographyColumns');
|
||||||
|
const proceduresParameters = require('./proceduresParameters');
|
||||||
|
|
||||||
const fk_keyColumnUsage = require('./fk_key_column_usage');
|
const fk_keyColumnUsage = require('./fk_key_column_usage');
|
||||||
const fk_referentialConstraints = require('./fk_referential_constraints');
|
const fk_referentialConstraints = require('./fk_referential_constraints');
|
||||||
@@ -39,4 +40,5 @@ module.exports = {
|
|||||||
uniqueNames,
|
uniqueNames,
|
||||||
geometryColumns,
|
geometryColumns,
|
||||||
geographyColumns,
|
geographyColumns,
|
||||||
|
proceduresParameters,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
module.exports = `
|
||||||
|
SELECT
|
||||||
|
proc.specific_schema AS specific_schema,
|
||||||
|
proc.routine_name AS routine_name,
|
||||||
|
proc.routine_type as routine_type,
|
||||||
|
args.parameter_name AS pure_name,
|
||||||
|
args.parameter_mode,
|
||||||
|
args.data_type AS data_type,
|
||||||
|
args.ordinal_position AS parameter_index,
|
||||||
|
CASE
|
||||||
|
WHEN args.parameter_mode IN ('OUT', 'INOUT') THEN TRUE
|
||||||
|
ELSE FALSE
|
||||||
|
END AS is_output_paramter
|
||||||
|
FROM
|
||||||
|
information_schema.routines proc
|
||||||
|
LEFT JOIN
|
||||||
|
information_schema.parameters args
|
||||||
|
ON proc.specific_schema = args.specific_schema
|
||||||
|
AND proc.specific_name = args.specific_name
|
||||||
|
WHERE
|
||||||
|
proc.routine_schema NOT IN ('pg_catalog', 'information_schema') -- Exclude system schemas
|
||||||
|
AND proc.routine_type IN ('PROCEDURE', 'FUNCTION') -- Filter for procedures
|
||||||
|
ORDER BY
|
||||||
|
specific_schema,
|
||||||
|
routine_name,
|
||||||
|
args.ordinal_position;
|
||||||
|
`;
|
||||||
Reference in New Issue
Block a user