import { IconDatabase } from "@tabler/icons-react"; import { useState } from "react"; import { Badge, Card, Col, Container, Row, Table } from "react-bootstrap"; import { useQuery } from "@tanstack/react-query"; import { getTables, getTableData } from "src/api/backend"; import { HasPermission, Loading } from "src/components"; import { ADMIN, VIEW } from "src/modules/Permissions"; export default function DatabaseManager() { const [activeTable, setActiveTable] = useState(null); const { data: tables, isLoading: tablesLoading } = useQuery({ queryKey: ["database-tables"], queryFn: getTables, }); const { data: tableData, isLoading: tableDataLoading } = useQuery({ queryKey: ["database-table", activeTable, 0, 50], queryFn: () => getTableData(activeTable as string, 0, 50), enabled: !!activeTable, }); // Select the first table by default when tables are loaded if (tables && tables.length > 0 && !activeTable) { setActiveTable(tables[0]); } const renderTableData = (data: any[]) => { if (!data || data.length === 0) return
No data
; // In SQLite, raw SQL mapping might mismatch explicit schemas, so strictly read keys from the first row. const columns = Object.keys(data[0]); return (
{columns.map((col: string) => ( ))} {data.map((row: any, i: number) => ( {columns.map((col: string) => ( ))} ))}
{col}
{row[col] === null ? ( NULL ) : typeof row[col] === "object" ? ( JSON.stringify(row[col]) ) : ( String(row[col]) )}
); }; return (

Database Manager

Super Admin Only
Tables
{tablesLoading &&
} {tables?.map((table: string) => ( ))}
{activeTable || "Select a table"}
{tableData && {tableData.total} rows}
{tableDataLoading ? (
) : ( tableData && renderTableData(tableData.rows) )}
); }