mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 05:16:00 +00:00
duckdb analyser fixes
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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})`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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[]}
|
||||||
|
|||||||
@@ -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`;
|
||||||
|
|||||||
@@ -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`;
|
||||||
|
|||||||
@@ -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`;
|
||||||
|
|||||||
Reference in New Issue
Block a user