mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
load row count
This commit is contained in:
parent
7137c4a1d4
commit
113016c25c
@ -269,7 +269,7 @@ export abstract class GridDisplay {
|
|||||||
this.columns.map((col) => ({ ...col, sourceAlias: 'basetbl' })),
|
this.columns.map((col) => ({ ...col, sourceAlias: 'basetbl' })),
|
||||||
'uniqueName'
|
'uniqueName'
|
||||||
);
|
);
|
||||||
const action = this.processReferences(select, displayedColumnInfo)
|
const action = this.processReferences(select, displayedColumnInfo);
|
||||||
this.applyFilterOnSelect(select, displayedColumnInfo);
|
this.applyFilterOnSelect(select, displayedColumnInfo);
|
||||||
this.applySortOnSelect(select, displayedColumnInfo);
|
this.applySortOnSelect(select, displayedColumnInfo);
|
||||||
if (action == 'loadRequired') {
|
if (action == 'loadRequired') {
|
||||||
@ -286,4 +286,18 @@ export abstract class GridDisplay {
|
|||||||
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCountQuery() {
|
||||||
|
const select = this.createSelect();
|
||||||
|
select.columns = [
|
||||||
|
{
|
||||||
|
exprType: 'raw',
|
||||||
|
sql: 'COUNT(*)',
|
||||||
|
alias: 'count',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
select.orderBy = null;
|
||||||
|
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,5 +23,9 @@ export function dumpSqlExpression(dmp: SqlDumper, expr: Expression) {
|
|||||||
case 'value':
|
case 'value':
|
||||||
dmp.put('%v', expr.value);
|
dmp.put('%v', expr.value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'raw':
|
||||||
|
dmp.put('%s', expr.sql);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,12 @@ export interface PlaceholderExpression {
|
|||||||
exprType: 'placeholder';
|
exprType: 'placeholder';
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Expression = ColumnRefExpression | ValueExpression | PlaceholderExpression;
|
export interface RawExpression {
|
||||||
|
exprType: 'raw';
|
||||||
|
sql: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Expression = ColumnRefExpression | ValueExpression | PlaceholderExpression | RawExpression;
|
||||||
export type OrderByExpression = Expression & { direction: 'ASC' | 'DESC' };
|
export type OrderByExpression = Expression & { direction: 'ASC' | 'DESC' };
|
||||||
|
|
||||||
export type ResultField = Expression & { alias?: string };
|
export type ResultField = Expression & { alias?: string };
|
||||||
|
@ -94,6 +94,13 @@ const FocusField = styled.input`
|
|||||||
top: -1000px;
|
top: -1000px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const RowCountLabel = styled.div`
|
||||||
|
position: absolute;
|
||||||
|
background-color: lightgoldenrodyellow;
|
||||||
|
right: 40px;
|
||||||
|
bottom: 20px;
|
||||||
|
`;
|
||||||
|
|
||||||
/** @param props {import('./types').DataGridProps} */
|
/** @param props {import('./types').DataGridProps} */
|
||||||
async function loadDataPage(props, offset, limit) {
|
async function loadDataPage(props, offset, limit) {
|
||||||
const { display, conid, database, jslid } = props;
|
const { display, conid, database, jslid } = props;
|
||||||
@ -133,6 +140,24 @@ function dataPageAvailable(props) {
|
|||||||
return !!sql;
|
return !!sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param props {import('./types').DataGridProps} */
|
||||||
|
async function loadRowCount(props) {
|
||||||
|
const { display, conid, database, jslid } = props;
|
||||||
|
const sql = display.getCountQuery();
|
||||||
|
|
||||||
|
const response = await axios.request({
|
||||||
|
url: 'database-connections/query-data',
|
||||||
|
method: 'post',
|
||||||
|
params: {
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
},
|
||||||
|
data: { sql },
|
||||||
|
});
|
||||||
|
|
||||||
|
return parseInt(response.data.rows[0].count);
|
||||||
|
}
|
||||||
|
|
||||||
/** @param props {import('./types').DataGridProps} */
|
/** @param props {import('./types').DataGridProps} */
|
||||||
export default function DataGridCore(props) {
|
export default function DataGridCore(props) {
|
||||||
const { conid, database, display, changeSetState, dispatchChangeSet, tabVisible } = props;
|
const { conid, database, display, changeSetState, dispatchChangeSet, tabVisible } = props;
|
||||||
@ -147,8 +172,9 @@ export default function DataGridCore(props) {
|
|||||||
loadedRows: [],
|
loadedRows: [],
|
||||||
isLoadedAll: false,
|
isLoadedAll: false,
|
||||||
loadedTime: new Date().getTime(),
|
loadedTime: new Date().getTime(),
|
||||||
|
allRowCount: null,
|
||||||
});
|
});
|
||||||
const { isLoading, loadedRows, isLoadedAll, loadedTime } = loadProps;
|
const { isLoading, loadedRows, isLoadedAll, loadedTime, allRowCount } = loadProps;
|
||||||
|
|
||||||
const loadedTimeRef = React.useRef(0);
|
const loadedTimeRef = React.useRef(0);
|
||||||
const focusFieldRef = React.useRef();
|
const focusFieldRef = React.useRef();
|
||||||
@ -186,11 +212,20 @@ export default function DataGridCore(props) {
|
|||||||
[selectedCells]
|
[selectedCells]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleLoadRowCount = async () => {
|
||||||
|
const rowCount = await loadRowCount(props);
|
||||||
|
setLoadProps({
|
||||||
|
...loadProps,
|
||||||
|
allRowCount: rowCount,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const loadNextData = async () => {
|
const loadNextData = async () => {
|
||||||
if (isLoading) return;
|
if (isLoading) return;
|
||||||
setLoadProps({
|
setLoadProps({
|
||||||
...loadProps,
|
...loadProps,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
|
allRowCount: null,
|
||||||
});
|
});
|
||||||
const loadStart = new Date().getTime();
|
const loadStart = new Date().getTime();
|
||||||
loadedTimeRef.current = loadStart;
|
loadedTimeRef.current = loadStart;
|
||||||
@ -205,6 +240,7 @@ export default function DataGridCore(props) {
|
|||||||
// nextRows = [];
|
// nextRows = [];
|
||||||
// }
|
// }
|
||||||
// console.log('nextRows', nextRows);
|
// console.log('nextRows', nextRows);
|
||||||
|
if (allRowCount == null) handleLoadRowCount();
|
||||||
const loadedInfo = {
|
const loadedInfo = {
|
||||||
loadedRows: [...loadedRows, ...nextRows],
|
loadedRows: [...loadedRows, ...nextRows],
|
||||||
loadedTime,
|
loadedTime,
|
||||||
@ -290,6 +326,7 @@ export default function DataGridCore(props) {
|
|||||||
|
|
||||||
const reload = () => {
|
const reload = () => {
|
||||||
setLoadProps({
|
setLoadProps({
|
||||||
|
allRowCount: null,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
loadedRows: [],
|
loadedRows: [],
|
||||||
isLoadedAll: false,
|
isLoadedAll: false,
|
||||||
@ -984,6 +1021,7 @@ export default function DataGridCore(props) {
|
|||||||
engine={display.engine}
|
engine={display.engine}
|
||||||
onConfirm={handleConfirmSql}
|
onConfirm={handleConfirmSql}
|
||||||
/>
|
/>
|
||||||
|
{allRowCount && <RowCountLabel>Rows: {allRowCount.toLocaleString()}</RowCountLabel>}
|
||||||
{props.toolbarPortalRef &&
|
{props.toolbarPortalRef &&
|
||||||
tabVisible &&
|
tabVisible &&
|
||||||
ReactDOM.createPortal(
|
ReactDOM.createPortal(
|
||||||
|
Loading…
Reference in New Issue
Block a user