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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(search): support regex table filtering
t8y2c87b4af61413
diff --git a/apps/desktop/src/lib/objectBrowserRows.ts b/apps/desktop/src/lib/objectBrowserRows.tsindex 25765fe2ca..a5ad68df4d 100644--- a/apps/desktop/src/lib/objectBrowserRows.ts+++ b/apps/desktop/src/lib/objectBrowserRows.ts@@ -1,5 +1,6 @@import type { ObjectInfo } from "@/types/database";import { createDatabaseObjectNameComparator, normalizeDatabaseObjectName } from "@/lib/tableTree";+import { parseSlashDelimitedRegexQuery } from "@/lib/searchPattern";export type ObjectBrowserRow = {id: string;@@ -100,6 +101,12 @@ function partitionParentName(name: string): string | null {export function filterObjectBrowserRows(rows: ObjectBrowserRow[], query: string): ObjectBrowserRow[] {const q = query.trim().toLowerCase();if (!q) return rows;+ const regex = parseSlashDelimitedRegexQuery(query.trim());+ if (regex) {+ return rows.filter((row) =>+ [row.name, row.type, row.comment].filter(Boolean).some((value) => regex.test(String(value))),+ );+ }return rows.filter((row) =>[row.name, row.type, row.comment].filter(Boolean).some((value) => String(value).toLowerCase().includes(q)),);diff --git a/apps/desktop/src/lib/searchPattern.ts b/apps/desktop/src/lib/searchPattern.tsnew file mode 100644index 0000000000..63f0e44a37--- /dev/null+++ b/apps/desktop/src/lib/searchPattern.ts@@ -0,0 +1,15 @@+export function parseSlashDelimitedRegexQuery(query: string): RegExp | null {+ if (!query.startsWith("/") || query.length < 2) return null;+ const lastSlash = query.lastIndexOf("/");+ if (lastSlash <= 0) return null;++ const source = query.slice(1, lastSlash);+ const flags = query.slice(lastSlash + 1);+ if (!/^[dgimsuvy]*$/.test(flags)) return null;++ try {+ return new RegExp(source, flags.includes("i") ? flags : `${flags}i`);+ } catch {+ return null;+ }+}diff --git a/apps/desktop/src/lib/sidebarSearch.ts b/apps/desktop/src/lib/sidebarSearch.tsindex 986af04a05..6edaeb6b03 100644--- a/apps/desktop/src/lib/sidebarSearch.ts+++ b/apps/desktop/src/lib/sidebarSearch.ts@@ -1,4 +1,13 @@-export type SidebarSearchMatchKind = "exact" | "prefix" | "word-prefix" | "substring" | "abbreviation" | "fuzzy";+import { parseSlashDelimitedRegexQuery } from "@/lib/searchPattern";++export type SidebarSearchMatchKind =+ | "exact"+ | "prefix"+ | "word-prefix"+ | "substring"+ | "abbreviation"+ | "fuzzy"+ | "regex";export interface SidebarSearchMatch {kind: SidebarSearchMatchKind;@@ -42,6 +51,9 @@ function matchesSubsequence(text: string, query: string): boolean {export function matchSidebarLabel(label: string, query: string): SidebarSearchMatch | null {if (!query) return null;+ const regex = parseSlashDelimitedRegexQuery(query);+ if (regex) return regex.test(label) ? { kind: "regex", score: 95 } : null;+if (label === query) return { kind: "exact", score: 100 };if (label.startsWith(query)) return { kind: "prefix", score: 90 };if (matchesWordPrefix(label, query)) return { kind: "word-prefix", score: 80 };diff --git a/packages/app-tests/objectBrowserRows.test.ts b/packages/app-tests/objectBrowserRows.test.tsindex 3c2726747b..9a0611bd80 100644--- a/packages/app-tests/objectBrowserRows.test.ts+++ b/packages/app-tests/objectBrowserRows.test.ts@@ -43,6 +43,24 @@ test("object browser search matches names, types, and comments but not schema na);});+test("object browser search supports slash-delimited regular expression queries", () => {+ const rows = buildObjectBrowserRows({+ objects: [+ { name: "sys_user_log", object_type: "TABLE", schema: "public" },+ { name: "sys_order_archive", object_type: "TABLE", schema: "public" },+ { name: "app_user_log", object_type: "TABLE", schema: "public" },+ ],+ database: "app",+ fallbackSchema: "public",+ needsSchema: true,+ });++ assert.deepEqual(+ filterObjectBrowserRows(rows, "/^sys_.*_log$/").map((row) => row.name),+ ["sys_user_log"],+ );+});+test("object browser rows preserve table timestamps and sort recent updates first", () => {const rows = buildObjectBrowserRows({objects: [diff --git a/packages/app-tests/sidebarSearch.test.ts b/packages/app-tests/sidebarSearch.test.tsindex 6a183c34c6..728db6722d 100644--- a/packages/app-tests/sidebarSearch.test.ts+++ b/packages/app-tests/sidebarSearch.test.ts@@ -32,3 +32,12 @@ test("keeps fuzzy subsequence matching inside a single identifier word", () => {assert.equal(matchSidebarLabel("user_profile", "up")?.kind, "abbreviation");assert.equal(matchSidebarLabel("user_profile", "urf"), null);});++test("matches slash-delimited regular expression queries case-insensitively by default", () => {+ assert.equal(matchSidebarLabel("SYS_USER_LOG", "/^sys_.*_log$/")?.kind, "regex");+ assert.equal(matchSidebarLabel("sys_user_archive", "/^sys_.*_log$/"), null);+});++test("keeps invalid regular expression queries from matching every label", () => {+ assert.equal(matchSidebarLabel("orders", "/["), null);+});