duckdb analyser fixes

This commit is contained in:
Jan Prochazka
2025-04-28 14:07:42 +02:00
parent 09b43a8e95
commit 1f68f62689
6 changed files with 21 additions and 17 deletions

View File

@@ -94,7 +94,7 @@ function mapViewRowToViewInfo(duckDbViewRow) {
pureName: duckDbViewRow.view_name,
schemaName: duckDbViewRow.schema_name,
objectId: duckDbViewRow.view_oid,
objectTypeField: 'view',
objectTypeField: 'views',
columns: [],
};
@@ -116,7 +116,7 @@ function mapRawTableToTableInfo(rawTableData) {
const pureName = rawTableData.table_name;
const schemaName = rawTableData.schema_name;
const objectId = rawTableData.table_oid;
const objectTypeField = 'table';
const objectTypeField = 'tables';
const objectComment = rawTableData.comment;
return {
@@ -156,7 +156,6 @@ function extractDataType(columnInfo) {
case 'VARCHAR':
case 'CHAR':
console.log('this', maxLength);
if (typeof maxLength === 'number' && maxLength > 0) {
return `${baseType}(${maxLength})`;
}

View File

@@ -16,18 +16,23 @@ class Analyser extends DatabaseAnalyser {
}
async _computeSingleObjectId() {
const { pureName } = this.singleObjectFilter;
this.singleObjectId = pureName;
const { schemaName, pureName } = this.singleObjectFilter;
this.singleObjectId = `${schemaName || 'main'}.${pureName}`;
}
createQuery(resFileName, typeFields) {
if (!sql[resFileName]) throw new Error(`Missing analyse file ${resFileName}`);
return super.createQuery(sql[resFileName], typeFields);
}
async _runAnalysis() {
const tablesResult = await this.driver.query(this.dbhan, sql.tables);
const columnsResult = await this.driver.query(this.dbhan, sql.columns);
const foreignKeysResult = await this.driver.query(this.dbhan, sql.foreignKeys);
const primaryKeysResult = await this.driver.query(this.dbhan, sql.primaryKeys);
const uniquesResults = await this.driver.query(this.dbhan, sql.uniques);
const indexesResult = await this.driver.query(this.dbhan, sql.indexes);
const viewsResult = await this.driver.query(this.dbhan, sql.views);
const tablesResult = await this.analyserQuery('tables', ['tables']);
const columnsResult = await this.analyserQuery('columns', ['tables']);
const foreignKeysResult = await this.analyserQuery('foreignKeys', ['tables']);
const primaryKeysResult = await this.analyserQuery('primaryKeys', ['tables']);
const uniquesResults = await this.analyserQuery('uniques', ['tables']);
const indexesResult = await this.analyserQuery('uniques', ['indexes']);
const viewsResult = await this.analyserQuery('views', ['views']);
/**
* @type {import('dbgate-types').ForeignKeyInfo[]}

View File

@@ -1 +1 @@
module.exports = `SELECT * from duckdb_columns() WHERE internal = false`;
module.exports = `SELECT * from duckdb_columns() WHERE internal = false and (schema_name || '.' || table_name) =OBJECT_ID_CONDITION`;

View File

@@ -1 +1 @@
module.exports = `SELECT * from duckdb_tables() WHERE internal = false`;
module.exports = `SELECT * from duckdb_tables() WHERE internal = false and (schema_name || '.' || table_name) =OBJECT_ID_CONDITION`;

View File

@@ -1 +1 @@
module.exports = `SELECT * FROM duckdb_views() WHERE internal = false`;
module.exports = `SELECT * FROM duckdb_views() WHERE internal = false and (schema_name || '.' || view_name) =OBJECT_ID_CONDITION`;