mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 12:56:01 +00:00
perspectives: show row count
This commit is contained in:
@@ -37,6 +37,7 @@ export class PerspectiveCacheTable {
|
|||||||
loadedAll: boolean;
|
loadedAll: boolean;
|
||||||
loadedRows: any[] = [];
|
loadedRows: any[] = [];
|
||||||
bindingGroups: { [bindingKey: string]: PerspectiveBindingGroup } = {};
|
bindingGroups: { [bindingKey: string]: PerspectiveBindingGroup } = {};
|
||||||
|
allRowCount: number = null;
|
||||||
|
|
||||||
get loadedCount() {
|
get loadedCount() {
|
||||||
return this.loadedRows.length;
|
return this.loadedRows.length;
|
||||||
|
|||||||
@@ -142,4 +142,32 @@ export class PerspectiveDataLoader {
|
|||||||
if (response.errorMessage) return response;
|
if (response.errorMessage) return response;
|
||||||
return response.rows;
|
return response.rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async loadRowCount(props: PerspectiveDataLoadProps) {
|
||||||
|
const { schemaName, pureName, bindingColumns, bindingValues, dataColumns, orderBy, condition } = props;
|
||||||
|
|
||||||
|
const select: Select = {
|
||||||
|
commandType: 'select',
|
||||||
|
from: {
|
||||||
|
name: { schemaName, pureName },
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
exprType: 'raw',
|
||||||
|
sql: 'COUNT(*)',
|
||||||
|
alias: 'count',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
where: this.buildCondition(props),
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await this.apiCall('database-connections/sql-select', {
|
||||||
|
conid: props.databaseConfig.conid,
|
||||||
|
database: props.databaseConfig.database,
|
||||||
|
select,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.errorMessage) return response;
|
||||||
|
return response.rows[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,4 +203,23 @@ export class PerspectiveDataProvider {
|
|||||||
|
|
||||||
return tableCache.getRowsResult(props);
|
return tableCache.getRowsResult(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async loadRowCount(props: PerspectiveDataLoadProps): Promise<number> {
|
||||||
|
const tableCache = this.cache.getTableCache(props);
|
||||||
|
|
||||||
|
if (tableCache.allRowCount != null) {
|
||||||
|
return tableCache.allRowCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await this.loader.loadRowCount({
|
||||||
|
...props,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.errorMessage) {
|
||||||
|
throw new Error(result.errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
tableCache.allRowCount = parseInt(result.count);
|
||||||
|
return tableCache.allRowCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
import { getPerspectiveNodeMenu } from './perspectiveMenu';
|
import { getPerspectiveNodeMenu } from './perspectiveMenu';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
import { getFilterValueExpression } from 'dbgate-filterparser';
|
import { getFilterValueExpression } from 'dbgate-filterparser';
|
||||||
|
import StatusBarTabItem from '../widgets/StatusBarTabItem.svelte';
|
||||||
|
|
||||||
const dbg = debug('dbgate:PerspectiveTable');
|
const dbg = debug('dbgate:PerspectiveTable');
|
||||||
export const activator = createActivator('PerspectiveTable', true, ['Designer']);
|
export const activator = createActivator('PerspectiveTable', true, ['Designer']);
|
||||||
@@ -54,6 +55,7 @@
|
|||||||
let domWrapper;
|
let domWrapper;
|
||||||
let domTable;
|
let domTable;
|
||||||
let errorMessage;
|
let errorMessage;
|
||||||
|
let rowCount;
|
||||||
let isLoading = false;
|
let isLoading = false;
|
||||||
const lastVisibleRowIndexRef = createRef(0);
|
const lastVisibleRowIndexRef = createRef(0);
|
||||||
const disableLoadNextRef = createRef(false);
|
const disableLoadNextRef = createRef(false);
|
||||||
@@ -128,10 +130,13 @@
|
|||||||
dataRows = rows;
|
dataRows = rows;
|
||||||
dbg('data rows', rows);
|
dbg('data rows', rows);
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
|
|
||||||
|
rowCount = await node.dataProvider.loadRowCount(root.getNodeLoadProps([]));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
errorMessage = err.message;
|
errorMessage = err.message;
|
||||||
dataRows = null;
|
dataRows = null;
|
||||||
|
rowCount = null;
|
||||||
}
|
}
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
// console.log('DISPLAY ROWS', rows);
|
// console.log('DISPLAY ROWS', rows);
|
||||||
@@ -531,6 +536,10 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if rowCount != null}
|
||||||
|
<StatusBarTabItem text={`Rows: ${rowCount.toLocaleString()}`} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.wrapper {
|
.wrapper {
|
||||||
overflow: scroll;
|
overflow: scroll;
|
||||||
|
|||||||
@@ -133,8 +133,8 @@
|
|||||||
$: tableInfo = rootDb?.tables.find(x => x.pureName == rootObject?.pureName && x.schemaName == rootObject?.schemaName);
|
$: tableInfo = rootDb?.tables.find(x => x.pureName == rootObject?.pureName && x.schemaName == rootObject?.schemaName);
|
||||||
$: viewInfo = rootDb?.views.find(x => x.pureName == rootObject?.pureName && x.schemaName == rootObject?.schemaName);
|
$: viewInfo = rootDb?.views.find(x => x.pureName == rootObject?.pureName && x.schemaName == rootObject?.schemaName);
|
||||||
|
|
||||||
$: dataProvider = new PerspectiveDataProvider(cache, loader);
|
|
||||||
$: loader = new PerspectiveDataLoader(apiCall);
|
$: loader = new PerspectiveDataLoader(apiCall);
|
||||||
|
$: dataProvider = new PerspectiveDataProvider(cache, loader);
|
||||||
$: root =
|
$: root =
|
||||||
tableInfo || viewInfo
|
tableInfo || viewInfo
|
||||||
? new PerspectiveTableNode(
|
? new PerspectiveTableNode(
|
||||||
|
|||||||
Reference in New Issue
Block a user