Skip to content

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

chore: retire node-sql-parser (#15395)

boojack2852b65e8af2
diff --git a/frontend/package.json b/frontend/package.json
index b5c0730437..f466a9d625 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -56,7 +56,6 @@
"nice-grpc-common": "^2.0.2",
"nice-grpc-error-details": "^0.2.8",
"nice-grpc-web": "^3.3.6",
- "node-sql-parser": "5.3.5",
"normalize-wheel": "^1.0.1",
"pev2": "1.12.1",
"pinia": "2.2.8",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index b92a01e0b8..549fd73b7e 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -121,9 +121,6 @@ importers:
nice-grpc-web:
specifier: ^3.3.6
version: 3.3.6([email protected])
- node-sql-parser:
- specifier: 5.3.5
- version: 5.3.5
normalize-wheel:
specifier: ^1.0.1
version: 1.0.1
@@ -1831,9 +1828,6 @@ packages:
resolution: {integrity: sha512-iclKEmOclXH2LGVkMkdal0+ffJphB3kbazakec96z1hW/CfJYmsZNFYLAmkpzePxKoKewXp2HSlsN6G4SG0b0g==}
- '@types/[email protected]':
- resolution: {integrity: sha512-eLYXDbZWXh2uxf+w8sXS8d6KSoXTswfps6fvCUuVAGN8eRpfe7h9eSRydxiSJvo9Bf+GzifsDOr9TMQlmJdmkw==}
-
resolution: {integrity: sha512-1MGjmAMux3OIyJ+iXfhJ5hNIzS+KjGJ05O3bF5Gen5TiJUFNK1bOp3VVV9SxXgz+hGwnBruBAWdAqhbB6ZHhSA==}
@@ -2270,10 +2264,6 @@ packages:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
- resolution: {integrity: sha512-QxD8cf2eVqJOOz63z6JIN9BzvVs/dlySa5HGSBH5xtR8dPteIRQnBxxKqkNTiT6jbDTF6jAfrd4oMcND9RGbQg==}
- engines: {node: '>=0.6'}
-
resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==}
engines: {node: '>=8'}
@@ -3737,10 +3727,6 @@ packages:
resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==}
- resolution: {integrity: sha512-DOR2PAe3gY5/fXmSvpTOpyv8+HkQ5jA9KShAEy7fVLaV8kVbeg8aa7qo0MdfqCDskwqjcakp0lS/Rnmg+iY/XQ==}
- engines: {node: '>=8'}
-
resolution: {integrity: sha512-taM24ViiimT/XntxbPyJQzCG+p4EKOpgD3mxFwW38mGjVUrfERQOeY4EDHjdnptttfHuHQXFx+lTP08Q+mLa/w==}
engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0}
@@ -6462,8 +6448,6 @@ snapshots:
'@types/[email protected]': {}
- '@types/[email protected]': {}
-
dependencies:
'@types/pouchdb-core': 7.0.15
@@ -7067,8 +7051,6 @@ snapshots:
-
@@ -8719,11 +8701,6 @@ snapshots:
- dependencies:
- '@types/pegjs': 0.10.6
- big-integer: 1.6.52
-
dependencies:
abbrev: 2.0.0
diff --git a/frontend/src/components/MonacoEditor/sqlParser.ts b/frontend/src/components/MonacoEditor/sqlParser.ts
deleted file mode 100644
index 0b9c29aafe..0000000000
--- a/frontend/src/components/MonacoEditor/sqlParser.ts
+++ /dev/null
@@ -1,83 +0,0 @@
-import { isObject, isArray } from "lodash-es";
-import type { AST } from "node-sql-parser";
-
-type ParseResult = {
- data: AST | AST[] | null;
- error: Error | null;
-};
-
-const DDL_TYPE = ["create", "alter", "drop"];
-const DML_TYPE = ["insert", "update", "delete"];
-const SELECT = "select";
-
-export const parseSQL = async (sql: string): Promise<ParseResult> => {
- const { Parser } = await import("node-sql-parser");
-
- if (sql === "") {
- return { data: [], error: null };
- }
-
- const parser = new Parser();
-
- try {
- const ast = parser.astify(sql);
- return { data: ast, error: null };
- } catch (error) {
- return { data: null, error: error as Error };
- }
-};
-
-export const isValidStatement = (data: ParseResult["data"]) => {
- // if parser returns the null AST. it's an invalid sql statement
- return data !== null;
-};
-
-export const isSelectStatement = (data: ParseResult["data"]) => {
- // 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 const isMultipleStatements = (data: ParseResult["data"]) => {
- // if the sql statement is an array and it's more than one statement
- return isArray(data) && data.length > 1;
-};
-
-export const isDDLStatement = (
- data: ParseResult["data"],
- method: "every" | "some" = "every"
-) => {
- // if the sql statement is an object, it's a single sql statement
- if (isObject(data) && !isArray(data)) {
- return DDL_TYPE.includes(data.type.toLowerCase());
- }
- // if the sql statement is an array, it's a multiple sql statements
- if (isArray(data)) {
- return data[method]((statement) =>
- DDL_TYPE.includes(statement.type.toLowerCase())
- );
- }
-};
-
-export const isDMLStatement = (
- data: ParseResult["data"],
- method: "every" | "some" = "every"
-) => {
- // if the sql statement is an object, it's a single sql statement
- if (isObject(data) && !isArray(data)) {
- return DML_TYPE.includes(data.type.toLowerCase());
- }
- // if the sql statement is an array, it's a multiple sql statements
- if (isArray(data)) {
- return data[method]((statement) =>
- DML_TYPE.includes(statement.type.toLowerCase())
- );
- }
-};
-
-export default parseSQL;
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.ts
index 040b85dcfc..0bf5e3756f 100644
--- a/frontend/src/composables/useExecuteSQL.ts
+++ b/frontend/src/composables/useExecuteSQL.ts
@@ -2,7 +2,6 @@ import Emittery from "emittery";
import { head, isEmpty } from "lodash-es";
import { Status } from "nice-grpc-common";
import { markRaw, reactive } from "vue";
-import { parseSQL } from "@/components/MonacoEditor/sqlParser";
import { sqlServiceClient } from "@/grpcweb";
import { t } from "@/plugins/i18n";
import {
@@ -198,13 +197,6 @@ const useExecuteSQL = () => {
const queryContext = tab.queryContext!;
const batchQueryContext = tab.batchQueryContext;
- const { data } = await parseSQL(params.statement);
-
- if (data === undefined) {
- notify("CRITICAL", t("sql-editor.notify-invalid-sql-statement"));
- return cleanup();
- }
-
const selectedDatabase = useDatabaseV1Store().getDatabaseByName(
params.connection.database
);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 425701ec6e..d70c787388 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1727,7 +1727,6 @@
"to-enable-admin-mode": "to enable the admin mode",
"notify-empty-statement": "Please input your SQL statements in the editor",
"goto-edit-schema-hint": "Please select a database connection from the top of the editor",
- "notify-invalid-sql-statement": "Invalid SQL statement.",
"can-not-execute-query": "Cannot execute query when loading data.",
"rows": "row | rows",
"vertical-display": "Vertical display",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 2f7d7b56ee..c81481ddc8 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1727,7 +1727,6 @@
"to-enable-admin-mode": "para habilitar el modo administrador",
"notify-empty-statement": "Ingrese sus declaraciones SQL en el editor",
"goto-edit-schema-hint": "Seleccione una conexión de base de datos desde la parte superior del editor",
- "notify-invalid-sql-statement": "Declaración SQL inválida.",
"can-not-execute-query": "No se puede ejecutar la consulta al cargar datos.",
"rows": "fila | filas",
"vertical-display": "Pantalla vertical",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 2802693525..3e31144283 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1727,7 +1727,6 @@
"to-enable-admin-mode": "管理者モードを有効にするには",
"notify-empty-statement": "エディターに SQL ステートメントを入力してください",
"goto-edit-schema-hint": "エディタの上部からデータベース接続を選択してください",
- "notify-invalid-sql-statement": "SQL ステートメントを確認してください。",
"can-not-execute-query": "データのロード中にクエリを実行できません",
"rows": "記録",
"vertical-display": "縦型表示",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 8a06dc5512..d9371f9345 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1727,7 +1727,6 @@
"to-enable-admin-mode": "để bật chế độ quản trị",
"notify-empty-statement": "Vui lòng nhập câu lệnh SQL của bạn vào trình soạn thảo",
"goto-edit-schema-hint": "Vui lòng chọn một kết nối cơ sở dữ liệu từ đầu trình soạn thảo",
- "notify-invalid-sql-statement": "Câu lệnh SQL không hợp lệ.",
"can-not-execute-query": "Không thể thực hiện truy vấn khi đang tải dữ liệu.",
"rows": "dòng | dòng",
"vertical-display": "Hiển thị dọc",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 2db0d74271..0e5ab48172 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1727,7 +1727,6 @@
"to-enable-admin-mode": "来开启管理员模式",
"notify-empty-statement": "请在编辑器中输入 SQL 语句",
"goto-edit-schema-hint": "请从编辑器顶部选择一个数据库连接",
- "notify-invalid-sql-statement": "请检查您的 SQL 语句。",
"can-not-execute-query": "加载数据时无法执行查询",
"rows": "条记录",
"vertical-display": "竖向展示",
diff --git a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
index 863ab8c839..07c90f9075 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
@@ -62,13 +62,11 @@
</template>
<script lang="ts" setup>
-import { computedAsync } from "@vueuse/core";
import { NAlert, NButton } from "naive-ui";
import { v4 as uuidv4 } from "uuid";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import { parseSQL, isDDLStatement } from "@/components/MonacoEditor/sqlParser";
import { EnvironmentV1Name } from "@/components/v2";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import {
@@ -94,9 +92,6 @@ const emit = defineEmits<{
(e: "close"): void;
}>();
-const DDLIssueTemplate = "bb.issue.database.schema.update";
-const DMLIssueTemplate = "bb.issue.database.data.update";
-
const router = useRouter();
const { t } = useI18n();
const tabStore = useSQLEditorTabStore();
@@ -110,11 +105,6 @@ const statement = computed(() => {
return tab?.selectedStatement || tab?.statement || "";
});
-const isDDL = computedAsync(async () => {
- const { data } = await parseSQL(statement.value);
- return data !== null ? isDDLStatement(data, "some") : false;
-}, false);
-
const actions = computed(() => {
type Actions = {
admin: boolean;
@@ -139,17 +129,13 @@ const actions = computed(() => {
const descriptions = computed(() => {
const descriptions = {
- want: isDDL.value
- ? t("database.edit-schema").toLowerCase()
- : t("database.change-data").toLowerCase(),
+ want: t("database.edit-schema").toLowerCase(),
action: "",
reaction: "",
};
const { admin, issue } = actions.value;
if (issue) {
- descriptions.action = isDDL.value
- ? t("database.edit-schema")
- : t("database.change-data");
+ descriptions.action = t("database.edit-schema");
descriptions.reaction = t("sql-editor.and-submit-an-issue");
} else if (admin) {
descriptions.action = t("sql-editor.admin-mode.self");
@@ -185,10 +171,8 @@ const gotoCreateIssue = () => {
issueSlug: "create",
},
query: {
- template: isDDL.value ? DDLIssueTemplate : DMLIssueTemplate,
- name: `[${db.databaseName}] ${
- isDDL.value ? "Edit schema" : "Change Data"
- }`,
+ template: "bb.issue.database.schema.update", // Default to DDL issue template.
+ name: `[${db.databaseName}] Update from SQL Editor`,
databaseList: db.name,
sqlStorageKey,
},