Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(sql-editor): fixed the bug #346 (#347)

Yunwei Xiaofe72a9579f57
diff --git a/frontend/src/components/MonacoEditor/sqlParser.ts b/frontend/src/components/MonacoEditor/sqlParser.ts
index fa6f08c46e..d09000e09e 100644
--- a/frontend/src/components/MonacoEditor/sqlParser.ts
+++ b/frontend/src/components/MonacoEditor/sqlParser.ts
@@ -1,4 +1,5 @@
import { Parser, AST } from "node-sql-parser";
+import { isObject, isArray } from "lodash-es";
type ParseResult = {
data: AST | AST[] | null;
@@ -23,10 +24,17 @@ export const isValidStatement = (sql: string) => {
export const isSelectStatement = (sql: string) => {
const { data } = parseSQL(sql);
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
+
// if parser returns the null AST. it's an invalid sql statement
- return data?.type.toLowerCase() === "select" || data === null;
+ if (data === null) return true;
+ // if the sql statement is an object, it's a single sql statement
+ if (isObject(data) && !isArray(data)) {
+ return data.type.toLowerCase() === "select";
+ }
+ // if the sql statement is an array, it's a multiple sql statements
+ if (isArray(data)) {
+ return data.every((statement) => statement.type.toLowerCase() === "select");
+ }
};
export default parseSQL;
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index 4295884708..85ef87ff35 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -8,6 +8,8 @@ import ViteComponents from "vite-plugin-components";
const SERVER_PORT = process.env.PORT || 3000;
const HTTPS_PORT = 443;
const r = (...args: string[]) => resolve(__dirname, ...args);
+const defineGlobal =
+ process.env.NODE_ENV === "development" ? { global: {} } : {};
export default defineConfig(() => {
// NOTE: the following lines is to solve https://github.com/gitpod-io/gitpod/issues/6719
@@ -16,6 +18,9 @@ export default defineConfig(() => {
process.env["GITPOD_WORKSPACE_ID"] !== null &&
process.env["GITPOD_WORKSPACE_ID"] !== undefined;
return {
+ define: {
+ ...defineGlobal,
+ },
plugins: [
vue(),
// https://github.com/intlify/vite-plugin-vue-i18n