mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 04:26:01 +00:00
row numbers in mssql
This commit is contained in:
@@ -75,9 +75,12 @@ class MsSqlAnalyser extends DatabaseAnalyser {
|
||||
const indexesRows = await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
|
||||
const indexcolsRows = await this.driver.query(this.pool, this.createQuery('indexcols', ['tables']));
|
||||
const defaultSchemaRows = await this.driver.query(this.pool, 'SELECT SCHEMA_NAME() as name');
|
||||
const tableSizes = await this.driver.query(this.pool, this.createQuery('tableSizes'));
|
||||
|
||||
const schemas = schemaRows.rows;
|
||||
|
||||
const tableSizesDict = _.mapValues(_.keyBy(tableSizes.rows, 'objectId'), 'tableRowCount');
|
||||
|
||||
const sqlCodeRows = await this.driver.query(
|
||||
this.pool,
|
||||
this.createQuery('loadSqlCode', ['views', 'procedures', 'functions', 'triggers'])
|
||||
@@ -120,6 +123,7 @@ class MsSqlAnalyser extends DatabaseAnalyser {
|
||||
..._.pick(col, ['columnName']),
|
||||
})),
|
||||
})),
|
||||
tableRowCount: tableSizesDict[row.objectId],
|
||||
}));
|
||||
|
||||
const views = viewsRows.rows.map(row => ({
|
||||
@@ -157,6 +161,7 @@ class MsSqlAnalyser extends DatabaseAnalyser {
|
||||
|
||||
async _getFastSnapshot() {
|
||||
const modificationsQueryData = await this.driver.query(this.pool, this.createQuery('modifications'));
|
||||
const tableSizes = await this.driver.query(this.pool, this.createQuery('tableSizes'));
|
||||
|
||||
const res = DatabaseAnalyser.createEmptyStructure();
|
||||
for (const item of modificationsQueryData.rows) {
|
||||
@@ -171,6 +176,13 @@ class MsSqlAnalyser extends DatabaseAnalyser {
|
||||
pureName,
|
||||
});
|
||||
}
|
||||
|
||||
for (const tableSize of tableSizes.rows) {
|
||||
const table = (res.tables || []).find(x => x.objectId == tableSize.objectId);
|
||||
if (table) {
|
||||
table.tableRowCount = tableSize.tableRowCount;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ const columns = require('./columns');
|
||||
const foreignKeys = require('./foreignKeys');
|
||||
const primaryKeys = require('./primaryKeys');
|
||||
const tables = require('./tables');
|
||||
const tableSizes = require('./tableSizes');
|
||||
const modifications = require('./modifications');
|
||||
const loadSqlCode = require('./loadSqlCode');
|
||||
const views = require('./views');
|
||||
@@ -24,4 +25,5 @@ module.exports = {
|
||||
getSchemas,
|
||||
indexes,
|
||||
indexcols,
|
||||
tableSizes,
|
||||
};
|
||||
|
||||
15
plugins/dbgate-plugin-mssql/src/backend/sql/tableSizes.js
Normal file
15
plugins/dbgate-plugin-mssql/src/backend/sql/tableSizes.js
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = `
|
||||
SELECT distinct
|
||||
t.object_id as objectId,
|
||||
p.rows AS tableRowCount
|
||||
FROM
|
||||
sys.tables t
|
||||
INNER JOIN
|
||||
sys.indexes i ON t.OBJECT_ID = i.object_id
|
||||
INNER JOIN
|
||||
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
|
||||
WHERE
|
||||
t.NAME NOT LIKE 'dt%'
|
||||
AND t.is_ms_shipped = 0
|
||||
AND i.OBJECT_ID > 255
|
||||
`;
|
||||
Reference in New Issue
Block a user