mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-22 17:00:21 +08:00
- 后端接入:新增独立 starrocks 可选驱动,复用 MySQL wire 协议并支持默认 9030 端口 - 驱动管理:补齐 manifest、build tag、revision、driver-agent provider 和构建脚本 - 前端接入:新增 StarRocks 连接类型、图标、能力矩阵、URI 解析、保存回显和 SQL 自动 LIMIT - 方言增强:新增 StarRocks 类型、关键字、函数补全和专属建表 SQL 生成 - 高级对象:支持物化视图对象浏览、Rollup 模板、外部 Catalog 模板和高级表设计器参数 - CI 发布:将 StarRocks driver-agent 纳入 dev/release 构建与 release 资产校验
153 lines
3.5 KiB
Go
153 lines
3.5 KiB
Go
package sync
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"GoNavi-Wails/internal/db"
|
|
)
|
|
|
|
func normalizeSyncMode(mode string) string {
|
|
m := strings.ToLower(strings.TrimSpace(mode))
|
|
switch m {
|
|
case "", "insert_update":
|
|
return "insert_update"
|
|
case "insert_only":
|
|
return "insert_only"
|
|
case "full_overwrite":
|
|
return "full_overwrite"
|
|
default:
|
|
return "insert_update"
|
|
}
|
|
}
|
|
|
|
func quoteIdentByType(dbType string, ident string) string {
|
|
if ident == "" {
|
|
return ident
|
|
}
|
|
|
|
switch normalizeMigrationDBType(dbType) {
|
|
case "mysql", "mariadb", "oceanbase", "diros", "starrocks", "sphinx", "clickhouse", "tdengine":
|
|
return "`" + strings.ReplaceAll(ident, "`", "``") + "`"
|
|
case "kingbase":
|
|
return db.QuoteKingbaseIdentifier(ident)
|
|
case "sqlserver":
|
|
escaped := strings.ReplaceAll(ident, "]", "]]")
|
|
return "[" + escaped + "]"
|
|
default:
|
|
return `"` + strings.ReplaceAll(ident, `"`, `""`) + `"`
|
|
}
|
|
}
|
|
|
|
func quoteQualifiedIdentByType(dbType string, ident string) string {
|
|
raw := strings.TrimSpace(ident)
|
|
if raw == "" {
|
|
return raw
|
|
}
|
|
|
|
normalizedType := normalizeMigrationDBType(dbType)
|
|
if normalizedType == "kingbase" {
|
|
schema, table := db.SplitKingbaseQualifiedName(raw)
|
|
if table == "" {
|
|
return quoteIdentByType(normalizedType, raw)
|
|
}
|
|
if schema == "" {
|
|
return quoteIdentByType(normalizedType, table)
|
|
}
|
|
return quoteIdentByType(normalizedType, schema) + "." + quoteIdentByType(normalizedType, table)
|
|
}
|
|
|
|
parts := strings.Split(raw, ".")
|
|
if len(parts) <= 1 {
|
|
return quoteIdentByType(normalizedType, raw)
|
|
}
|
|
|
|
quotedParts := make([]string, 0, len(parts))
|
|
for _, part := range parts {
|
|
part = strings.TrimSpace(part)
|
|
if part == "" {
|
|
continue
|
|
}
|
|
quotedParts = append(quotedParts, quoteIdentByType(normalizedType, part))
|
|
}
|
|
|
|
if len(quotedParts) == 0 {
|
|
return quoteIdentByType(normalizedType, raw)
|
|
}
|
|
return strings.Join(quotedParts, ".")
|
|
}
|
|
|
|
func normalizeSchemaAndTable(dbType string, dbName string, tableName string) (string, string) {
|
|
rawTable := strings.TrimSpace(tableName)
|
|
rawDB := strings.TrimSpace(dbName)
|
|
if rawTable == "" {
|
|
return rawDB, rawTable
|
|
}
|
|
|
|
normalizedType := normalizeMigrationDBType(dbType)
|
|
if normalizedType == "kingbase" {
|
|
schema, table := db.SplitKingbaseQualifiedName(rawTable)
|
|
if schema != "" && table != "" {
|
|
return schema, table
|
|
}
|
|
if table != "" {
|
|
return "public", table
|
|
}
|
|
}
|
|
|
|
if parts := strings.SplitN(rawTable, ".", 2); len(parts) == 2 {
|
|
schema := strings.TrimSpace(parts[0])
|
|
table := strings.TrimSpace(parts[1])
|
|
if schema != "" && table != "" {
|
|
return schema, table
|
|
}
|
|
}
|
|
|
|
switch normalizedType {
|
|
case "postgres", "kingbase", "highgo", "vastbase", "opengauss":
|
|
return "public", rawTable
|
|
case "duckdb":
|
|
return "main", rawTable
|
|
default:
|
|
return rawDB, rawTable
|
|
}
|
|
}
|
|
|
|
func qualifiedNameForQuery(dbType string, schema string, table string, original string) string {
|
|
raw := strings.TrimSpace(original)
|
|
if raw == "" {
|
|
return raw
|
|
}
|
|
if strings.Contains(raw, ".") {
|
|
return raw
|
|
}
|
|
|
|
switch normalizeMigrationDBType(dbType) {
|
|
case "postgres", "kingbase", "highgo", "vastbase", "opengauss":
|
|
s := strings.TrimSpace(schema)
|
|
if s == "" {
|
|
s = "public"
|
|
}
|
|
if table == "" {
|
|
return raw
|
|
}
|
|
return s + "." + table
|
|
case "duckdb":
|
|
s := strings.TrimSpace(schema)
|
|
if s == "" {
|
|
s = "main"
|
|
}
|
|
if table == "" {
|
|
return raw
|
|
}
|
|
return s + "." + table
|
|
case "mysql", "mariadb", "oceanbase", "diros", "starrocks", "sphinx", "clickhouse", "tdengine":
|
|
s := strings.TrimSpace(schema)
|
|
if s == "" || table == "" {
|
|
return table
|
|
}
|
|
return s + "." + table
|
|
default:
|
|
return table
|
|
}
|
|
}
|