Skip to content

Commit 78c1fce

Browse files
committed
fix read only query identifier
1 parent b89f69e commit 78c1fce

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/utils.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Model } from "./stores/chat";
2-
import { getExecutionType } from "sql-query-identifier";
2+
import { identify } from "sql-query-identifier";
33

44
export function safeJSONStringify(value: any, ...args: any): string {
55
return JSON.stringify(
@@ -51,15 +51,15 @@ export function isAbortError(error: unknown) {
5151

5252
export function parseHeaders(text: string): Record<string, string> {
5353
const headers = {};
54-
const lines = text.split('\n');
54+
const lines = text.split("\n");
5555

5656
for (let line of lines) {
5757
line = line.trim();
58-
if (!line || !line.includes(':')) continue;
58+
if (!line || !line.includes(":")) continue;
5959

60-
const [key, ...rest] = line.split(':');
60+
const [key, ...rest] = line.split(":");
6161
const trimmedKey = key.trim();
62-
const value = rest.join(':').trim();
62+
const value = rest.join(":").trim();
6363

6464
if (trimmedKey) {
6565
headers[trimmedKey] = value;
@@ -75,6 +75,13 @@ export function matchModel(a: Model, b?: Model) {
7575
}
7676

7777
export function isReadQuery(query: string) {
78-
const type = getExecutionType(query);
79-
return type === "LISTING" || type === "INFORMATION";
78+
try {
79+
// Not sure, but assume that identify() can throw an error
80+
return identify(query).every(
81+
({ executionType }) =>
82+
executionType === "LISTING" || executionType === "INFORMATION",
83+
);
84+
} catch (e) {
85+
return false;
86+
}
8087
}

0 commit comments

Comments
 (0)