Skip to content

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

refactor: move validator

d-bytebase7d636e08c537
diff --git a/backend/plugin/parser/sql/utils.go b/backend/plugin/parser/sql/utils.go
index f76422f836..2d3bf205c9 100644
--- a/backend/plugin/parser/sql/utils.go
+++ b/backend/plugin/parser/sql/utils.go
@@ -169,3 +169,20 @@ func ExtractSensitiveField(dbType db.Type, statement string, currentDatabase str
return nil, nil
}
}
+
+// ValidateSQLForEditor validates the SQL statement for editor.
+// We support the following SQLs:
+// 1. EXPLAIN statement, except EXPLAIN ANALYZE
+// 2. SELECT statement
+//
+// We also support CTE with SELECT statements, but not with DML statements.
+func ValidateSQLForEditor(engine EngineType, statement string) bool {
+ switch engine {
+ case Postgres, Redshift, RisingWave:
+ return pgparser.ValidateSQLForEditor(statement)
+ case MySQL, TiDB, MariaDB, OceanBase:
+ return mysqlparser.ValidateSQLForEditor(statement)
+ default:
+ return standardparser.ValidateSQLForEditor(statement)
+ }
+}
diff --git a/backend/plugin/parser/sql/validate_sql_for_editor.go b/backend/plugin/parser/sql/validate_sql_for_editor.go
deleted file mode 100644
index bbe183774a..0000000000
--- a/backend/plugin/parser/sql/validate_sql_for_editor.go
+++ /dev/null
@@ -1,24 +0,0 @@
-package parser
-
-import (
- mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
- pgparser "github.com/bytebase/bytebase/backend/plugin/parser/pg"
- standardparser "github.com/bytebase/bytebase/backend/plugin/parser/standard"
-)
-
-// ValidateSQLForEditor validates the SQL statement for editor.
-// We support the following SQLs:
-// 1. EXPLAIN statement, except EXPLAIN ANALYZE
-// 2. SELECT statement
-//
-// We also support CTE with SELECT statements, but not with DML statements.
-func ValidateSQLForEditor(engine EngineType, statement string) bool {
- switch engine {
- case Postgres, Redshift, RisingWave:
- return pgparser.ValidateSQLForEditor(statement)
- case MySQL, TiDB, MariaDB, OceanBase:
- return mysqlparser.ValidateSQLForEditor(statement)
- default:
- return standardparser.ValidateSQLForEditor(statement)
- }
-}