feat(database): search and pagination on result query (#1432)

Adds a search bar to query result grids (match case / words / regex, previous/next occurrence, Filter rows) and a pager for console results (first/previous/next/last, page size). Later pages re-run the read-only query with a skip, which every driver reads past without decoding, so only one page crosses IPC; Last counts rows with the statement wrapped so a trailing line comment can't swallow the closing parenthesis.

Closes #1431

Co-authored-by: kidp2h <40386174+kidp2h@users.noreply.github.com>
This commit is contained in:
Nguyen Thinh
2026-11-05 12:54:15 +08:00
committed by GitHub
parent 7856fabbfe
commit 75c4ca0be8
22 changed files with 973 additions and 97 deletions
@@ -0,0 +1,28 @@
import { describe, expect, it } from "vitest";
import { isReadOnlyQuery } from "./readOnly";
describe("isReadOnlyQuery", () => {
it("accepts queries that only read", () => {
for (const text of [
"SELECT * FROM t",
"with x as (select 1) select * from x",
"VALUES (1), (2)",
"show tables",
"(select 1) union (select 2)",
])
expect(isReadOnlyQuery(text, "postgres"), text).toBe(true);
});
it("rejects statements that change data", () => {
for (const text of [
"DELETE FROM t RETURNING *",
"UPDATE t SET a = 1 RETURNING a",
"INSERT INTO t VALUES (1) RETURNING id",
"with d as (delete from t returning *) select * from d",
"select * into t2 from t",
"select * from t for update",
"select nextval('s')",
])
expect(isReadOnlyQuery(text, "postgres"), text).toBe(false);
});
});
+15
View File
@@ -0,0 +1,15 @@
import type { DbDriver } from "@/platform/ipc";
import { lex } from "./lexer";
/** Statements that only read. */
const READ_VERBS = new Set(["SELECT", "WITH", "VALUES", "TABLE", "SHOW", "DESCRIBE", "DESC", "EXPLAIN", "PRAGMA"]);
/** Words that make a reading statement write (data-modifying CTEs, SELECT INTO, row locks, sequences). */
const WRITES = new Set(["INSERT", "UPDATE", "DELETE", "MERGE", "INTO", "NEXTVAL", "SETVAL", "CALL", "EXEC", "EXECUTE"]);
/** Whether running `text` again only reads (paging a result re-runs its query). */
export function isReadOnlyQuery(text: string, driver: DbDriver): boolean {
const tokens = lex(text, driver).tokens;
const first = tokens.find((t) => t.text !== "(");
if (!first || first.kind !== "word" || !READ_VERBS.has(first.upper)) return false;
return !tokens.some((t) => t.kind === "word" && WRITES.has(t.upper));
}