mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 21:56:00 +00:00
AI refactor
This commit is contained in:
@@ -35,7 +35,7 @@ const crypto = require('crypto');
|
|||||||
const loadModelTransform = require('../utility/loadModelTransform');
|
const loadModelTransform = require('../utility/loadModelTransform');
|
||||||
const exportDbModelSql = require('../utility/exportDbModelSql');
|
const exportDbModelSql = require('../utility/exportDbModelSql');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const { getAuthProxyUrl } = require('../utility/authProxy');
|
const { callTextToSqlApi } = require('../utility/authProxy');
|
||||||
|
|
||||||
const logger = getLogger('databaseConnections');
|
const logger = getLogger('databaseConnections');
|
||||||
|
|
||||||
@@ -570,29 +570,13 @@ module.exports = {
|
|||||||
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||||
const { structure } = existing || {};
|
const { structure } = existing || {};
|
||||||
if (!structure) return { errorMessage: 'No database structure' };
|
if (!structure) return { errorMessage: 'No database structure' };
|
||||||
const model = {
|
|
||||||
tables: structure.tables.map(table => ({
|
|
||||||
name: table.pureName,
|
|
||||||
columns: table.columns.map(column => column.columnName),
|
|
||||||
primaryKey: table.primaryKey?.columns?.map(column => column.columnName),
|
|
||||||
foreignKeys: table.foreignKeys.map(fk => ({
|
|
||||||
refTable: fk.refTableName,
|
|
||||||
column: fk.columns[0]?.columnName,
|
|
||||||
refColumn: fk.columns[0]?.refColumnName,
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
|
|
||||||
const resp = await axios.default.post(`${getAuthProxyUrl()}/text-to-sql`, {
|
const res = await callTextToSqlApi(text, structure, dialect);
|
||||||
text,
|
|
||||||
model,
|
|
||||||
dialect,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!resp.data.sql) {
|
if (!res.sql) {
|
||||||
return { errorMessage: 'No SQL generated' };
|
return { errorMessage: 'No SQL generated' };
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp.data;
|
return res;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ async function getAwsIamToken(params) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function callTextToSqlApi(text, structure, dialect) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isAuthProxySupported,
|
isAuthProxySupported,
|
||||||
authProxyGetRedirectUrl,
|
authProxyGetRedirectUrl,
|
||||||
@@ -32,4 +36,5 @@ module.exports = {
|
|||||||
getAuthProxyUrl,
|
getAuthProxyUrl,
|
||||||
supportsAwsIam,
|
supportsAwsIam,
|
||||||
getAwsIamToken,
|
getAwsIamToken,
|
||||||
|
callTextToSqlApi,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user