mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 04:26:01 +00:00
feat: add object ids to firebird queries
This commit is contained in:
@@ -16,35 +16,46 @@ class Analyser extends DatabaseAnalyser {
|
||||
}
|
||||
|
||||
async _runAnalysis() {
|
||||
const tablesResult = await this.driver.query(this.dbhan, sql.tables);
|
||||
const columnsResult = await this.driver.query(this.dbhan, sql.columns);
|
||||
const triggersResult = await this.driver.query(this.dbhan, sql.triggers);
|
||||
const primaryKeysResult = await this.driver.query(this.dbhan, sql.primaryKeys);
|
||||
const foreignKeysResult = await this.driver.query(this.dbhan, sql.foreignKeys);
|
||||
const functionsResults = await this.driver.query(this.dbhan, sql.functions);
|
||||
const functionParametersResults = await this.driver.query(this.dbhan, sql.functionParameters);
|
||||
const proceduresResults = await this.driver.query(this.dbhan, sql.procedures);
|
||||
const procedureParametersResults = await this.driver.query(this.dbhan, sql.procedureParameters);
|
||||
const tablesResult = await this.analyserQuery(sql.tables, ['tables']);
|
||||
const columnsResult = await this.analyserQuery(sql.columns, ['tables', 'views']);
|
||||
const triggersResult = await this.analyserQuery(sql.triggers, ['triggers']);
|
||||
const primaryKeysResult = await this.analyserQuery(sql.primaryKeys, ['primaryKeys']);
|
||||
const foreignKeysResult = await this.analyserQuery(sql.foreignKeys, ['foreignKeys']);
|
||||
const functionsResults = await this.analyserQuery(sql.functions, ['functions']);
|
||||
const functionParametersResults = await this.analyserQuery(sql.functionParameters, ['functions']);
|
||||
const proceduresResults = await this.analyserQuery(sql.procedures, ['procedures']);
|
||||
const procedureParametersResults = await this.analyserQuery(sql.procedureParameters, ['procedures']);
|
||||
|
||||
const columns = columnsResult.rows?.map(column => ({
|
||||
...column,
|
||||
objectId: `tables:${column.columnName}`,
|
||||
dataType: getDataTypeString(column),
|
||||
defaultValue: getFormattedDefaultValue(column.defaultValue),
|
||||
}));
|
||||
|
||||
const triggers = triggersResult.rows?.map(i => ({
|
||||
...i,
|
||||
objectId: `triggers:${i.pureName}`,
|
||||
eventType: getTriggerEventType(i.TRIGGERTYPE),
|
||||
triggerTiming: getTriggerTiming(i.TRIGGERTYPE),
|
||||
createSql: getTriggerCreateSql(i),
|
||||
}));
|
||||
|
||||
const primaryKeys = primaryKeysResult.rows ?? [];
|
||||
const primaryKeys =
|
||||
primaryKeysResult.rows?.map(primaryKey => ({
|
||||
...primaryKey,
|
||||
objectId: `tables:${primaryKey.pureName}`,
|
||||
})) ?? [];
|
||||
|
||||
const foreignKeys = foreignKeysResult.rows ?? [];
|
||||
const foreignKeys =
|
||||
foreignKeysResult.rows?.map(foreignKey => ({
|
||||
...foreignKey,
|
||||
objectId: `tables:${foreignKey.pureName}`,
|
||||
})) ?? [];
|
||||
|
||||
const functions = functionsResults.rows?.map(func => ({
|
||||
...func,
|
||||
objectId: `functions:${func.pureName}`,
|
||||
returnType: functionParametersResults.rows?.filter(
|
||||
param => param.owningObjectName === func.pureName && param.parameterMode === 'RETURN'
|
||||
)?.dataType,
|
||||
@@ -58,6 +69,7 @@ class Analyser extends DatabaseAnalyser {
|
||||
|
||||
const procedures = proceduresResults.rows.map(proc => ({
|
||||
...proc,
|
||||
objectId: `procedures:${proc.pureName}`,
|
||||
parameters: procedureParametersResults.rows
|
||||
?.filter(param => param.owningObjectName === proc.pureName)
|
||||
.map(param => ({
|
||||
@@ -69,6 +81,7 @@ class Analyser extends DatabaseAnalyser {
|
||||
const tables =
|
||||
tablesResult.rows?.map(table => ({
|
||||
...table,
|
||||
objectId: `tables:${table.pureName}`,
|
||||
columns: columns.filter(column => column.tableName === table.pureName),
|
||||
primaryKey: DatabaseAnalyser.extractPrimaryKeys(table, primaryKeys),
|
||||
foreignKeys: DatabaseAnalyser.extractForeignKeys(table, foreignKeys),
|
||||
@@ -81,6 +94,12 @@ class Analyser extends DatabaseAnalyser {
|
||||
procedures,
|
||||
};
|
||||
}
|
||||
|
||||
async _computeSingleObjectId() {
|
||||
const { typeField, pureName } = this.singleObjectFilter;
|
||||
console.log('Computing single object ID for', typeField, pureName);
|
||||
this.singleObjectId = `${typeField}:${pureName}`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Analyser;
|
||||
|
||||
@@ -37,6 +37,8 @@ LEFT JOIN
|
||||
rdb$collations co ON f.rdb$collation_id = co.rdb$collation_id
|
||||
WHERE
|
||||
r.rdb$system_flag = 0
|
||||
AND
|
||||
('columns:' || CAST(TRIM(rf.rdb$field_name) AS VARCHAR(255))) =OBJECT_ID_CONDITION
|
||||
ORDER BY
|
||||
"tableName", rf.rdb$field_position;
|
||||
`;
|
||||
|
||||
@@ -27,6 +27,8 @@ JOIN
|
||||
AND iseg_fk.RDB$FIELD_POSITION = iseg_pk.RDB$FIELD_POSITION -- Critical for matching columns in composite keys
|
||||
WHERE
|
||||
rc_fk.RDB$CONSTRAINT_TYPE = 'FOREIGN KEY'
|
||||
AND
|
||||
('tables:' || TRIM(rc_fk.RDB$RELATION_NAME)) =OBJECT_ID_CONDITION
|
||||
ORDER BY
|
||||
"pureName",
|
||||
"constraintName",
|
||||
|
||||
@@ -9,7 +9,8 @@ SELECT
|
||||
FROM
|
||||
RDB$FUNCTIONS F
|
||||
WHERE
|
||||
COALESCE(F.RDB$SYSTEM_FLAG, 0) = 0 -- User-defined functions
|
||||
COALESCE(F.RDB$SYSTEM_FLAG, 0) = 0 -- User-defined functions
|
||||
AND ('funcitons:' || TRIM(F.RDB$FUNCTION_NAME)) =OBJECT_ID_CONDITION
|
||||
ORDER BY
|
||||
"pureName";
|
||||
`;
|
||||
|
||||
@@ -20,6 +20,7 @@ JOIN
|
||||
WHERE
|
||||
rc.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY'
|
||||
AND COALESCE(rel.RDB$SYSTEM_FLAG, 0) = 0 -- Typically, you only want user-defined tables
|
||||
AND ('tables:' || TRIM(rc.RDB$RELATION_NAME)) =OBJECT_ID_CONDITION
|
||||
ORDER BY
|
||||
"pureName",
|
||||
"constraintName",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
module.exports = `
|
||||
SELECT
|
||||
TRIM(P.RDB$PROCEDURE_NAME) AS "pureName",
|
||||
TRIM(P.RDB$PROCEDURE_NAME) AS "objectId", -- Using procedure name as a practical objectId
|
||||
TRIM('PROCEDURE') AS "objectTypeField",
|
||||
TRIM(P.RDB$DESCRIPTION) AS "objectComment",
|
||||
P.RDB$PROCEDURE_SOURCE AS "createSql", -- Contains the PSQL body
|
||||
@@ -11,6 +10,7 @@ FROM
|
||||
WHERE
|
||||
COALESCE(P.RDB$SYSTEM_FLAG, 0) = 0 -- Filter for user-defined procedures
|
||||
AND P.RDB$PROCEDURE_TYPE IS NOT NULL -- Ensure it's a valid procedure type (0, 1, or 2)
|
||||
AND ('procedures:' || TRIM(P.RDB$PROCEDURE_NAME)) =OBJECT_ID_CONDITION
|
||||
ORDER BY
|
||||
"pureName";
|
||||
`;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
module.exports = `
|
||||
SELECT
|
||||
module.exports = `SELECT
|
||||
TRIM(RDB$RELATION_NAME) AS "pureName",
|
||||
RDB$DESCRIPTION AS "objectComment",
|
||||
RDB$FORMAT AS "objectTypeField"
|
||||
FROM RDB$RELATIONS
|
||||
WHERE RDB$SYSTEM_FLAG = 0 -- only user-defined tables
|
||||
ORDER BY "pureName";
|
||||
`;
|
||||
FROM
|
||||
RDB$RELATIONS
|
||||
WHERE
|
||||
RDB$SYSTEM_FLAG = 0 -- only user-defined tables
|
||||
AND
|
||||
('tables:' || TRIM(RDB$RELATION_NAME)) =OBJECT_ID_CONDITION
|
||||
ORDER BY
|
||||
"pureName";`;
|
||||
|
||||
@@ -8,5 +8,6 @@ FROM
|
||||
RDB$TRIGGERS rtr
|
||||
JOIN RDB$RELATIONS rel ON rtr.RDB$RELATION_NAME = rel.RDB$RELATION_NAME
|
||||
WHERE rtr.RDB$SYSTEM_FLAG = 0
|
||||
AND ('triggers:' || TRIM(rtr.RDB$TRIGGER_NAME)) =OBJECT_ID_CONDITION
|
||||
ORDER BY rtr.RDB$TRIGGER_NAME
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user