table structure tab WIP

This commit is contained in:
Jan Prochazka
2020-02-02 11:31:41 +01:00
parent d22058382f
commit af80a2799f
18 changed files with 318 additions and 57 deletions

View File

@@ -8,4 +8,11 @@ module.exports = {
const res = await databaseConnections.sendRequest(opened, { msgtype: 'tableData', schemaName, pureName });
return res;
},
tableInfo_meta: 'get',
async tableInfo({ conid, database, schemaName, pureName }) {
const opened = await databaseConnections.ensureOpened(conid, database);
const table = opened.structure.tables.find(x => x.pureName == pureName && x.schemaName == schemaName);
return table;
},
};

View File

@@ -1,5 +1,6 @@
const fs = require('fs-extra');
const path = require('path');
const _ = require('lodash');
const DatabaseAnalayser = require('../default/DatabaseAnalyser');
@@ -27,13 +28,18 @@ class MsSqlAnalyser extends DatabaseAnalayser {
}
async runAnalysis() {
const tables = await this.driver.query(this.pool, await this.createQuery('tables.sql'));
// for (const table of tables) {
// table.name = {
// schema: table.schemaName,
// name: table.tableName,
// };
// }
this.result.tables = tables.rows;
const columns = await this.driver.query(this.pool, await this.createQuery('columns.sql'));
this.result.tables = tables.rows.map(table => ({
...table,
columns: columns.rows
.filter(col => col.objectId == table.objectId)
.map(({ isNullable, isIdentity, ...col }) => ({
...col,
notNull: isNullable != 'True',
autoIncrement: isIdentity == 'True',
})),
}));
}
}

View File

@@ -0,0 +1,13 @@
select c.name as columnName, t.name as dataType, c.object_id as objectId, c.is_identity as isIdentity,
c.max_length as maxLength, c.precision, c.scale, c.is_nullable as isNullable,
d.definition as defaultValue, d.name as defaultConstraint,
m.definition as computedExpression, m.is_persisted as isPersisted, c.column_id as columnId,
-- TODO only if version >= 2008
c.is_sparse as isSparse
from sys.columns c
inner join sys.types t on c.system_type_id = t.system_type_id and c.user_type_id = t.user_type_id
inner join sys.objects o on c.object_id = o.object_id
left join sys.default_constraints d on c.default_object_id = d.object_id
left join sys.computed_columns m on m.object_id = c.object_id and m.column_id = c.column_id
where o.type = 'U' and o.object_id =[OBJECT_ID_CONDITION]
order by c.column_id

View File

@@ -1,5 +1,5 @@
select
o.name as pureName, s.name as schemaName, o.object_id,
o.name as pureName, s.name as schemaName, o.object_id as objectId,
o.create_date, o.modify_date
from sys.tables o
inner join sys.schemas s on o.schema_id = s.schema_id