perspectives: show row count

This commit is contained in:
Jan Prochazka
2022-09-22 18:23:04 +02:00
parent 59efdd735c
commit 83693e9f2c
5 changed files with 58 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ export class PerspectiveCacheTable {
loadedAll: boolean;
loadedRows: any[] = [];
bindingGroups: { [bindingKey: string]: PerspectiveBindingGroup } = {};
allRowCount: number = null;
get loadedCount() {
return this.loadedRows.length;

View File

@@ -142,4 +142,32 @@ export class PerspectiveDataLoader {
if (response.errorMessage) return response;
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];
}
}

View File

@@ -203,4 +203,23 @@ export class PerspectiveDataProvider {
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;
}
}