mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 04:26:01 +00:00
sqlite table analyser
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const _ = require('lodash');
|
||||
const { DatabaseAnalyser } = require('dbgate-tools');
|
||||
|
||||
class Analyser extends DatabaseAnalyser {
|
||||
@@ -7,14 +8,50 @@ class Analyser extends DatabaseAnalyser {
|
||||
|
||||
async _runAnalysis() {
|
||||
const tables = await this.driver.query(this.pool, "select * from sqlite_master where type='table'");
|
||||
console.log('tables', tables);
|
||||
console.log('TABLES', tables);
|
||||
|
||||
const tableSqls = _.zipObject(
|
||||
tables.rows.map((x) => x.name),
|
||||
tables.rows.map((x) => x.sql)
|
||||
);
|
||||
|
||||
const tableList = tables.rows.map((x) => ({
|
||||
pureName: x.name,
|
||||
objectId: x.name,
|
||||
}));
|
||||
|
||||
for (const tableName of this.getRequestedObjectPureNames(
|
||||
'tables',
|
||||
tables.rows.map((x) => x.name)
|
||||
)) {
|
||||
const info = await this.driver.query(this.pool, `pragma table_info('${tableName}')`);
|
||||
const tableObj = tableList.find((x) => x.pureName == tableName);
|
||||
tableObj.columns = info.rows.map((col) => ({
|
||||
columnName: col.name,
|
||||
dataType: col.type,
|
||||
notNull: !!col.notnull,
|
||||
defaultValue: col.dflt_value == null ? undefined : col.dflt_value,
|
||||
autoIncrement: tableSqls[tableName].toLowerCase().includes('autoincrement') && !!col.pk,
|
||||
}));
|
||||
|
||||
const pkColumns = info.rows
|
||||
.filter((x) => x.pk)
|
||||
.map((col) => ({
|
||||
columnName: col.name,
|
||||
}));
|
||||
|
||||
if (pkColumns.length > 0) {
|
||||
tableObj.primaryKey = {
|
||||
columns: pkColumns,
|
||||
};
|
||||
}
|
||||
|
||||
// console.log(info);
|
||||
}
|
||||
|
||||
const res = this.mergeAnalyseResult(
|
||||
{
|
||||
tables: tables.rows.map((x) => ({
|
||||
pureName: x.name,
|
||||
objectId: x.name,
|
||||
})),
|
||||
tables: tableList,
|
||||
},
|
||||
(x) => x.pureName
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ const Dumper = require('./Dumper');
|
||||
const dialect = {
|
||||
limitSelect: true,
|
||||
rangeSelect: true,
|
||||
offsetFetchRangeSyntax: true,
|
||||
offsetFetchRangeSyntax: false,
|
||||
stringEscapeChar: "'",
|
||||
fallbackDataType: 'nvarchar(max)',
|
||||
quoteIdentifier(s) {
|
||||
|
||||
Reference in New Issue
Block a user