mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-30 00:19:35 +00:00
## 背景说明 为 Redis 数据库浏览器增加键统计功能,显示已加载 key 数/总 key 数, 并在动态加载、删除、清空时实时更新。 ## 修改内容 - 新增 \RedisDatabaseInfo\ 结构体(db + keys),替代原来的 \Vec<u32>\ - \list_databases\ 返回每个 db 的 key 数量(解析 INFO keyspace) - \scan_keys_page\ 增加 DBSIZE 调用获取 total_keys - 前端 TreeNode 增加 loadedKeyCount/totalKeyCount 字段 - 树节点标签动态显示 \db0 (loaded/total)\ 格式 - 新增 \updateRedisDbKeyStats\ 在加载/删除/清空时更新统计 ## 测试 - 建议补充 list_keyspace_databases 解析异常输入的单测 - 建议补充 redisDbLabel 边界值测试
310 lines
6.0 KiB
TypeScript
310 lines
6.0 KiB
TypeScript
export type DatabaseType =
|
|
| "mysql"
|
|
| "postgres"
|
|
| "sqlite"
|
|
| "redis"
|
|
| "duckdb"
|
|
| "clickhouse"
|
|
| "sqlserver"
|
|
| "mongodb"
|
|
| "oracle"
|
|
| "elasticsearch"
|
|
| "doris"
|
|
| "starrocks"
|
|
| "redshift"
|
|
| "dameng"
|
|
| "gaussdb"
|
|
| "kingbase"
|
|
| "vastbase"
|
|
| "goldendb"
|
|
| "h2"
|
|
| "snowflake"
|
|
| "trino"
|
|
| "hive"
|
|
| "db2"
|
|
| "informix"
|
|
| "neo4j"
|
|
| "cassandra"
|
|
| "bigquery"
|
|
| "kylin"
|
|
| "sundb"
|
|
| "jdbc";
|
|
|
|
export interface ConnectionConfig {
|
|
id: string;
|
|
name: string;
|
|
db_type: DatabaseType;
|
|
driver_profile?: string;
|
|
driver_label?: string;
|
|
url_params?: string;
|
|
host: string;
|
|
port: number;
|
|
username: string;
|
|
password: string;
|
|
database?: string;
|
|
color?: string;
|
|
ssh_enabled?: boolean;
|
|
ssh_host?: string;
|
|
ssh_port?: number;
|
|
ssh_user?: string;
|
|
ssh_password?: string;
|
|
ssh_key_path?: string;
|
|
ssh_key_passphrase?: string;
|
|
ssh_expose_lan?: boolean;
|
|
ssh_connect_timeout_secs?: number;
|
|
proxy_enabled?: boolean;
|
|
proxy_type?: "socks5" | "http";
|
|
proxy_host?: string;
|
|
proxy_port?: number;
|
|
proxy_username?: string;
|
|
proxy_password?: string;
|
|
ssl?: boolean;
|
|
sysdba?: boolean;
|
|
connection_string?: string;
|
|
jdbc_driver_class?: string;
|
|
jdbc_driver_paths?: string[];
|
|
}
|
|
|
|
export interface PluginDriverManifest {
|
|
id: string;
|
|
label: string;
|
|
kind: string;
|
|
database_type?: string;
|
|
}
|
|
|
|
export interface PluginManifest {
|
|
id: string;
|
|
name: string;
|
|
version?: string;
|
|
protocol_version?: number;
|
|
description?: string;
|
|
executable?: string;
|
|
drivers: PluginDriverManifest[];
|
|
}
|
|
|
|
export interface InstalledPlugin {
|
|
manifest: PluginManifest;
|
|
path: string;
|
|
}
|
|
|
|
export interface JdbcDriverInfo {
|
|
name: string;
|
|
path: string;
|
|
size: number;
|
|
}
|
|
|
|
export interface JdbcPluginStatus {
|
|
installed: boolean;
|
|
version?: string | null;
|
|
protocol_version?: number | null;
|
|
compatible: boolean;
|
|
path: string;
|
|
}
|
|
|
|
export interface DatabaseInfo {
|
|
name: string;
|
|
}
|
|
|
|
export interface TableInfo {
|
|
name: string;
|
|
table_type: string;
|
|
comment?: string | null;
|
|
}
|
|
|
|
export type DatabaseObjectType = "TABLE" | "VIEW" | "PROCEDURE" | "FUNCTION";
|
|
|
|
export interface ObjectInfo {
|
|
name: string;
|
|
object_type: DatabaseObjectType | string;
|
|
schema?: string | null;
|
|
comment?: string | null;
|
|
}
|
|
|
|
export type ObjectSourceKind = "VIEW" | "PROCEDURE" | "FUNCTION";
|
|
|
|
export interface ObjectSource {
|
|
name: string;
|
|
object_type: ObjectSourceKind;
|
|
schema?: string | null;
|
|
source: string;
|
|
}
|
|
|
|
export interface ColumnInfo {
|
|
name: string;
|
|
data_type: string;
|
|
is_nullable: boolean;
|
|
column_default: string | null;
|
|
is_primary_key: boolean;
|
|
extra: string | null;
|
|
comment?: string | null;
|
|
numeric_precision?: number | null;
|
|
numeric_scale?: number | null;
|
|
character_maximum_length?: number | null;
|
|
}
|
|
|
|
export interface IndexInfo {
|
|
name: string;
|
|
columns: string[];
|
|
is_unique: boolean;
|
|
is_primary: boolean;
|
|
filter?: string | null;
|
|
index_type?: string | null;
|
|
included_columns?: string[] | null;
|
|
comment?: string | null;
|
|
}
|
|
|
|
export interface ForeignKeyInfo {
|
|
name: string;
|
|
column: string;
|
|
ref_table: string;
|
|
ref_column: string;
|
|
}
|
|
|
|
export interface TriggerInfo {
|
|
name: string;
|
|
event: string;
|
|
timing: string;
|
|
}
|
|
|
|
export interface QueryResult {
|
|
columns: string[];
|
|
rows: (string | number | boolean | null)[][];
|
|
affected_rows: number;
|
|
execution_time_ms: number;
|
|
truncated?: boolean;
|
|
}
|
|
|
|
export type TreeNodeType =
|
|
| "connection"
|
|
| "connection-group"
|
|
| "database"
|
|
| "schema"
|
|
| "table"
|
|
| "view"
|
|
| "procedure"
|
|
| "function"
|
|
| "group-columns"
|
|
| "group-indexes"
|
|
| "group-fkeys"
|
|
| "group-triggers"
|
|
| "group-tables"
|
|
| "group-views"
|
|
| "group-procedures"
|
|
| "group-functions"
|
|
| "object-browser"
|
|
| "saved-sql-root"
|
|
| "saved-sql-folder"
|
|
| "saved-sql-file"
|
|
| "column"
|
|
| "index"
|
|
| "fkey"
|
|
| "trigger"
|
|
| "redis-db"
|
|
| "mongo-db"
|
|
| "mongo-collection";
|
|
|
|
export interface ConnectionGroup {
|
|
id: string;
|
|
name: string;
|
|
collapsed: boolean;
|
|
}
|
|
|
|
export type SidebarOrderEntry =
|
|
| { type: "group"; id: string; connectionIds: string[] }
|
|
| { type: "connection"; id: string };
|
|
|
|
export interface SidebarLayout {
|
|
groups: ConnectionGroup[];
|
|
order: SidebarOrderEntry[];
|
|
}
|
|
|
|
export interface TreeNode {
|
|
id: string;
|
|
label: string;
|
|
type: TreeNodeType;
|
|
children?: TreeNode[];
|
|
isLoading?: boolean;
|
|
isExpanded?: boolean;
|
|
pinned?: boolean;
|
|
connectionId?: string;
|
|
database?: string;
|
|
schema?: string;
|
|
tableName?: string;
|
|
objectCount?: number;
|
|
loadedKeyCount?: number;
|
|
totalKeyCount?: number;
|
|
hiddenChildren?: TreeNode[];
|
|
savedSqlId?: string;
|
|
savedSqlFolderId?: string;
|
|
meta?: ColumnInfo | IndexInfo | ForeignKeyInfo | TriggerInfo;
|
|
}
|
|
|
|
export interface QueryTab {
|
|
id: string;
|
|
title: string;
|
|
connectionId: string;
|
|
database: string;
|
|
schema?: string;
|
|
sql: string;
|
|
savedSqlId?: string;
|
|
lastExecutedSql?: string;
|
|
resultBaseSql?: string;
|
|
resultSortedSql?: string;
|
|
pinned?: boolean;
|
|
result?: QueryResult;
|
|
results?: QueryResult[];
|
|
activeResultIndex?: number;
|
|
explainPlan?: import("@/lib/explainPlan").ParsedExplainPlan;
|
|
explainError?: string;
|
|
explainSql?: string;
|
|
lastExplainedSql?: string;
|
|
isExecuting: boolean;
|
|
isCancelling?: boolean;
|
|
executionId?: string;
|
|
isExplaining?: boolean;
|
|
explainExecutionId?: string;
|
|
mode: "data" | "query" | "redis" | "mongo" | "objects";
|
|
objectBrowser?: {
|
|
schema?: string;
|
|
objectType?: "tables";
|
|
};
|
|
tableMeta?: {
|
|
schema?: string;
|
|
tableName: string;
|
|
columns: ColumnInfo[];
|
|
primaryKeys: string[];
|
|
};
|
|
queryAnalysis?: {
|
|
schema?: string;
|
|
tableName: string;
|
|
selectStar: boolean;
|
|
columns: string[];
|
|
};
|
|
whereInput?: string;
|
|
}
|
|
|
|
export interface SavedSqlFolder {
|
|
id: string;
|
|
connectionId: string;
|
|
name: string;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface SavedSqlFile {
|
|
id: string;
|
|
connectionId: string;
|
|
folderId?: string;
|
|
name: string;
|
|
database: string;
|
|
schema?: string;
|
|
sql: string;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface SavedSqlLibrary {
|
|
folders: SavedSqlFolder[];
|
|
files: SavedSqlFile[];
|
|
}
|