mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 06:46:00 +00:00
feat: add uniques to firebird
This commit is contained in:
@@ -26,21 +26,24 @@ class Analyser extends DatabaseAnalyser {
|
||||
const proceduresResults = await this.analyserQuery(sql.procedures, ['procedures']);
|
||||
const procedureParametersResults = await this.analyserQuery(sql.procedureParameters, ['procedures']);
|
||||
const viewsResults = await this.analyserQuery(sql.views, ['views']);
|
||||
const unqiuesResults = await this.analyserQuery(sql.uniques, ['tables']);
|
||||
|
||||
const columns = columnsResult.rows?.map(column => ({
|
||||
...column,
|
||||
objectId: `tables:${column.columnName}`,
|
||||
dataType: getDataTypeString(column),
|
||||
defaultValue: getFormattedDefaultValue(column.defaultValue),
|
||||
}));
|
||||
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 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?.map(primaryKey => ({
|
||||
@@ -54,30 +57,45 @@ class Analyser extends DatabaseAnalyser {
|
||||
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,
|
||||
parameters: functionParametersResults.rows
|
||||
?.filter(param => param.owningObjectName === func.pureName)
|
||||
.map(param => ({
|
||||
...param,
|
||||
dataType: getDataTypeString(param),
|
||||
})),
|
||||
}));
|
||||
const functions =
|
||||
functionsResults.rows?.map(func => ({
|
||||
...func,
|
||||
objectId: `functions:${func.pureName}`,
|
||||
returnType: functionParametersResults.rows?.filter(
|
||||
param => param.owningObjectName === func.pureName && param.parameterMode === 'RETURN'
|
||||
)?.dataType,
|
||||
parameters: functionParametersResults.rows
|
||||
?.filter(param => param.owningObjectName === func.pureName)
|
||||
.map(param => ({
|
||||
...param,
|
||||
dataType: getDataTypeString(param),
|
||||
})),
|
||||
})) ?? [];
|
||||
|
||||
const procedures = proceduresResults.rows.map(proc => ({
|
||||
...proc,
|
||||
objectId: `procedures:${proc.pureName}`,
|
||||
parameters: procedureParametersResults.rows
|
||||
?.filter(param => param.owningObjectName === proc.pureName)
|
||||
.map(param => ({
|
||||
...param,
|
||||
dataType: getDataTypeString(param),
|
||||
})),
|
||||
}));
|
||||
const uniques =
|
||||
unqiuesResults.rows?.map(unique => ({
|
||||
pureName: unique.pureName,
|
||||
constraintName: unique.constraintName,
|
||||
constraintType: unique.constraintType,
|
||||
columns: [
|
||||
{
|
||||
columnName: unique.columnName,
|
||||
isDescending: unique.isDescending,
|
||||
},
|
||||
],
|
||||
})) ?? [];
|
||||
|
||||
const procedures =
|
||||
proceduresResults.rows?.map(proc => ({
|
||||
...proc,
|
||||
objectId: `procedures:${proc.pureName}`,
|
||||
parameters: procedureParametersResults.rows
|
||||
?.filter(param => param.owningObjectName === proc.pureName)
|
||||
.map(param => ({
|
||||
...param,
|
||||
dataType: getDataTypeString(param),
|
||||
})),
|
||||
})) ?? [];
|
||||
|
||||
const tables =
|
||||
tablesResult.rows?.map(table => ({
|
||||
@@ -86,7 +104,9 @@ class Analyser extends DatabaseAnalyser {
|
||||
columns: columns.filter(column => column.tableName === table.pureName),
|
||||
primaryKey: DatabaseAnalyser.extractPrimaryKeys(table, primaryKeys),
|
||||
foreignKeys: DatabaseAnalyser.extractForeignKeys(table, foreignKeys),
|
||||
uniques: uniques.filter(unique => unique.pureName === table.pureName),
|
||||
})) ?? [];
|
||||
console.log(uniques);
|
||||
|
||||
const views =
|
||||
viewsResults.rows?.map(view => ({
|
||||
|
||||
@@ -9,6 +9,7 @@ const functionParameters = require('./functionParameters');
|
||||
const procedures = require('./procedures');
|
||||
const procedureParameters = require('./procedureParameters');
|
||||
const views = require('./views');
|
||||
const uniques = require('./uniques');
|
||||
|
||||
module.exports = {
|
||||
version,
|
||||
@@ -22,4 +23,5 @@ module.exports = {
|
||||
functionParameters,
|
||||
procedures,
|
||||
procedureParameters,
|
||||
uniques,
|
||||
};
|
||||
|
||||
23
plugins/dbgate-plugin-firebird/src/backend/sql/uniques.js
Normal file
23
plugins/dbgate-plugin-firebird/src/backend/sql/uniques.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = `
|
||||
SELECT
|
||||
TRIM(rc.RDB$CONSTRAINT_NAME) AS "constraintName", -- Name of the constraint
|
||||
TRIM('unique') AS "constraintType", -- Type of the constraint
|
||||
TRIM(rc.RDB$RELATION_NAME) AS "pureName", -- Context: Table the constraint is on
|
||||
|
||||
-- Column specific fields from RDB$INDEX_SEGMENTS for the backing index
|
||||
TRIM(s.RDB$FIELD_NAME) AS "columnName", -- Name of the column in the unique key
|
||||
CASE COALESCE(i.RDB$INDEX_TYPE, 0) -- isDescending: 0 for ASC (default), 1 for DESC for the backing index
|
||||
WHEN 1 THEN TRUE
|
||||
ELSE FALSE
|
||||
END AS "isDescending"
|
||||
FROM
|
||||
RDB$RELATION_CONSTRAINTS rc
|
||||
JOIN
|
||||
-- RDB$INDEX_NAME in RDB$RELATION_CONSTRAINTS is the name of the index that enforces the UNIQUE constraint
|
||||
RDB$INDICES i ON rc.RDB$INDEX_NAME = i.RDB$INDEX_NAME
|
||||
JOIN
|
||||
RDB$INDEX_SEGMENTS s ON i.RDB$INDEX_NAME = s.RDB$INDEX_NAME
|
||||
WHERE
|
||||
rc.RDB$CONSTRAINT_TYPE = 'UNIQUE' -- Filter for UNIQUE constraints
|
||||
AND COALESCE(i.RDB$SYSTEM_FLAG, 0) = 0 -- Typically, backing indexes for user UQ constraints are user-related.
|
||||
`;
|
||||
Reference in New Issue
Block a user