дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +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]>
79 рядки
2.5 KiB
TypeScript
79 рядки
2.5 KiB
TypeScript
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);
|
|
});
|
|
|
|
it("classifies Snowflake statements", () => {
|
|
for (const text of [
|
|
"SELECT src:a::string FROM t // insert",
|
|
"with x as (select 1) select * from x",
|
|
"SHOW TABLES IN SCHEMA db.public",
|
|
"describe table t",
|
|
"DESC VIEW v",
|
|
"EXPLAIN SELECT 1",
|
|
"LIST @my_stage/path",
|
|
"ls @~",
|
|
"TABLE t",
|
|
"VALUES (1), (2)",
|
|
"select $1 from @my_stage/data (file_format => 'ff')",
|
|
])
|
|
expect(isReadOnlyQuery(text, "snowflake"), text).toBe(true);
|
|
for (const text of [
|
|
"COPY INTO t FROM @my_stage",
|
|
"PUT file:///tmp/a.csv @my_stage",
|
|
"GET @my_stage file:///tmp/",
|
|
"REMOVE @my_stage/path",
|
|
"rm @~/x",
|
|
"MERGE INTO t USING s ON t.id = s.id WHEN MATCHED THEN UPDATE SET a = 1",
|
|
"CALL my_proc()",
|
|
"EXECUTE IMMEDIATE $$ select 1 $$",
|
|
"USE SCHEMA public",
|
|
"ALTER SESSION SET TIMEZONE = 'UTC'",
|
|
"CREATE OR REPLACE TABLE t (a int)",
|
|
"DROP TABLE t",
|
|
"UNDROP TABLE t",
|
|
"TRUNCATE TABLE t",
|
|
"GRANT SELECT ON t TO ROLE r",
|
|
"REVOKE SELECT ON t FROM ROLE r",
|
|
"BEGIN",
|
|
"COMMIT",
|
|
"ROLLBACK",
|
|
"SET v = 1",
|
|
"UNSET v",
|
|
"INSERT INTO t VALUES (1)",
|
|
"UPDATE t SET a = 1",
|
|
"DELETE FROM t",
|
|
"select seq.nextval",
|
|
"select system$cancel_query('x')",
|
|
"select * from table(result_scan(last_query_id()))",
|
|
"show tables ->> delete from t",
|
|
])
|
|
expect(isReadOnlyQuery(text, "snowflake"), text).toBe(false);
|
|
// Stage listings are Snowflake's alone.
|
|
expect(isReadOnlyQuery("LIST @my_stage", "postgres")).toBe(false);
|
|
});
|
|
});
|