mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
duckdb analyser fixes
This commit is contained in:
@@ -92,10 +92,10 @@ export class DatabaseAnalyser {
|
||||
this.singleObjectFilter = { ...name, typeField };
|
||||
await this._computeSingleObjectId();
|
||||
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 =
|
||||
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);
|
||||
// console.log('SINGLE OBJECT', obj);
|
||||
return obj;
|
||||
|
||||
@@ -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})`;
|
||||
}
|
||||
|
||||
@@ -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[]}
|
||||
|
||||
@@ -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