mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-12 01:19:40 +08:00
- MariaDB:MySQL驱动占位,默认端口3306,归类关系型数据库 - Vastbase(海量):PG驱动占位,默认端口5432,归类国产数据库 - HighGo(瀚高):PG驱动,支持SM3认证扩展,归类国产数据库 - MongoDB:官方驱动实现,归类NoSQL - SQL Server:微软官方驱动实现,归类关系型数据库 - ConnectionModal 新增数据源选项卡与默认端口配置 - database.go 新增5种类型的实例化分支 - 同步更新 db_context、methods_db、sql_sanitize、methods_file、sql_helpers 类型判断 - 新增 HighGo SM3 驱动集成指南
113 lines
2.4 KiB
Go
113 lines
2.4 KiB
Go
package sync
|
|
|
|
import "strings"
|
|
|
|
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 dbType {
|
|
case "mysql", "mariadb":
|
|
return "`" + strings.ReplaceAll(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
|
|
}
|
|
|
|
parts := strings.Split(raw, ".")
|
|
if len(parts) <= 1 {
|
|
return quoteIdentByType(dbType, raw)
|
|
}
|
|
|
|
quotedParts := make([]string, 0, len(parts))
|
|
for _, part := range parts {
|
|
part = strings.TrimSpace(part)
|
|
if part == "" {
|
|
continue
|
|
}
|
|
quotedParts = append(quotedParts, quoteIdentByType(dbType, part))
|
|
}
|
|
|
|
if len(quotedParts) == 0 {
|
|
return quoteIdentByType(dbType, 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
|
|
}
|
|
|
|
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 strings.ToLower(strings.TrimSpace(dbType)) {
|
|
case "postgres", "kingbase", "vastbase":
|
|
return "public", 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 strings.ToLower(strings.TrimSpace(dbType)) {
|
|
case "postgres", "kingbase", "vastbase":
|
|
s := strings.TrimSpace(schema)
|
|
if s == "" {
|
|
s = "public"
|
|
}
|
|
if table == "" {
|
|
return raw
|
|
}
|
|
return s + "." + table
|
|
case "mysql", "mariadb":
|
|
s := strings.TrimSpace(schema)
|
|
if s == "" || table == "" {
|
|
return table
|
|
}
|
|
return s + "." + table
|
|
default:
|
|
return table
|
|
}
|
|
}
|