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

@@ -92,10 +92,10 @@ export class DatabaseAnalyser {
this.singleObjectFilter = { ...name, typeField }; this.singleObjectFilter = { ...name, typeField };
await this._computeSingleObjectId(); await this._computeSingleObjectId();
const res = this.addEngineField(await this._runAnalysis()); const res = this.addEngineField(await this._runAnalysis());
// console.log('SINGLE OBJECT RES', res); // console.log('SINGLE OBJECT RES', JSON.stringify(res, null, 2));
const obj = const obj =
res[typeField]?.length == 1 res[typeField]?.length == 1
? res[typeField][0] ? res[typeField]?.find(x => x.pureName.toLowerCase() == name.pureName.toLowerCase())
: res[typeField]?.find(x => x.pureName == name.pureName && x.schemaName == name.schemaName); : res[typeField]?.find(x => x.pureName == name.pureName && x.schemaName == name.schemaName);
// console.log('SINGLE OBJECT', obj); // console.log('SINGLE OBJECT', obj);
return obj; return obj;

View File

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

View File

@@ -16,18 +16,23 @@ class Analyser extends DatabaseAnalyser {
} }
async _computeSingleObjectId() { async _computeSingleObjectId() {
const { pureName } = this.singleObjectFilter; const { schemaName, pureName } = this.singleObjectFilter;
this.singleObjectId = pureName; 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() { async _runAnalysis() {
const tablesResult = await this.driver.query(this.dbhan, sql.tables); const tablesResult = await this.analyserQuery('tables', ['tables']);
const columnsResult = await this.driver.query(this.dbhan, sql.columns); const columnsResult = await this.analyserQuery('columns', ['tables']);
const foreignKeysResult = await this.driver.query(this.dbhan, sql.foreignKeys); const foreignKeysResult = await this.analyserQuery('foreignKeys', ['tables']);
const primaryKeysResult = await this.driver.query(this.dbhan, sql.primaryKeys); const primaryKeysResult = await this.analyserQuery('primaryKeys', ['tables']);
const uniquesResults = await this.driver.query(this.dbhan, sql.uniques); const uniquesResults = await this.analyserQuery('uniques', ['tables']);
const indexesResult = await this.driver.query(this.dbhan, sql.indexes); const indexesResult = await this.analyserQuery('uniques', ['indexes']);
const viewsResult = await this.driver.query(this.dbhan, sql.views); const viewsResult = await this.analyserQuery('views', ['views']);
/** /**
* @type {import('dbgate-types').ForeignKeyInfo[]} * @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`;