Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.0 KB
Raw Blame
import { normalizeResultPageSize } from "@/lib/dataGrid/paginationPageSize";

export function gridFsTotalPages(totalCount: number, pageSize: number): number {
  const normalizedPageSize = Math.max(1, normalizeResultPageSize(pageSize));
  const normalizedTotal = Number.isFinite(totalCount) ? Math.max(0, Math.floor(totalCount)) : 0;
  return Math.max(1, Math.ceil(normalizedTotal / normalizedPageSize));
}

export function clampGridFsPage(page: number, totalCount: number, pageSize: number): number {
  const lastPage = gridFsTotalPages(totalCount, pageSize) - 1;
  if (!Number.isFinite(page)) return 0;
  return Math.max(0, Math.min(Math.floor(page), lastPage));
}

export function paginateGridFsItems<T>(items: readonly T[], page: number, pageSize: number): T[] {
  const normalizedPageSize = Math.max(1, normalizeResultPageSize(pageSize));
  const safePage = clampGridFsPage(page, items.length, normalizedPageSize);
  const start = safePage * normalizedPageSize;
  return items.slice(start, start + normalizedPageSize);
}