дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
Snowflake is a built-in data source kind: connection dialog, key-pair, browser single sign-on, password or token sign-in, the database tree, SQL consoles, and Snowflake-aware SQL assistance and syntax colours. The driver speaks Snowflake's session protocol over the existing reqwest + rustls stack, with no JDBC/ODBC or native library and no new package. Metadata is read with SHOW / DESCRIBE, which need no running warehouse; introspected names are kept on disk for completion. Co-authored-by: vvnadolskyy <[email protected]>
25 рядки
1.3 KiB
TypeScript
25 рядки
1.3 KiB
TypeScript
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"]);
|
|
|
|
/** Snowflake's stage listings read too. */
|
|
const SNOWFLAKE_READ_VERBS = new Set(["LIST", "LS"]);
|
|
/** Snowflake functions that act on the account or depend on the statements run before. */
|
|
const SNOWFLAKE_WRITES = /^(SYSTEM\$.*|LAST_QUERY_ID|RESULT_SCAN)$/;
|
|
|
|
/** 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 !== "(");
|
|
const snowflake = driver === "snowflake";
|
|
if (!first || first.kind !== "word") return false;
|
|
if (!READ_VERBS.has(first.upper) && !(snowflake && SNOWFLAKE_READ_VERBS.has(first.upper))) return false;
|
|
return !tokens.some(
|
|
(t) => t.kind === "word" && (WRITES.has(t.upper) || (snowflake && SNOWFLAKE_WRITES.test(t.upper))),
|
|
);
|
|
}
|